Ver Fonte

docs: Talk about how to use S3 alternatives

Renée Kooi há 7 anos atrás
pai
commit
e811649c9c
1 ficheiros alterados com 40 adições e 0 exclusões
  1. 40 0
      website/src/docs/aws-s3.md

+ 40 - 0
website/src/docs/aws-s3.md

@@ -171,6 +171,46 @@ uppy.use(AwsS3, {
 
 
 See the [aws-presigned-url example in the uppy repository](https://github.com/transloadit/uppy/tree/master/examples/aws-presigned-url) for a small example that implements both the server-side and the client-side.
 See the [aws-presigned-url example in the uppy repository](https://github.com/transloadit/uppy/tree/master/examples/aws-presigned-url) for a small example that implements both the server-side and the client-side.
 
 
+### S3 Alternatives
+
+Many other object storage providers have an identical API to S3, so you can use the AwsS3 plugin with them. You do have to provide a custom signing endpoint for these providers. You can use the official AWS SDK for the server-side language of your choice to create one of these endpoints fairly easily.
+
+For example, with DigitalOcean Spaces, you could use the client-side AwsS3 plugin configuration from the [previous example](#Generating-a-presigned-upload-URL-server-side), and create a signing endpoint using [express](https://expressjs.com) and the [aws-sdk](https://npmjs.com/package/aws-sdk) for Node.js:
+
+```js
+const S3 = require('aws-sdk/clients/s3')
+const app = require('express')()
+
+const s3 = new S3({
+  endpoint: 'YOUR_REGION.digitaloceanspaces.com',
+  accessKeyId: 'YOUR_ACCESS_KEY',
+  secretAccessKey: 'YOUR_SECRET_KEY'
+})
+
+app.post('/params', (req, res) => {
+  const { filename, contentType } = req.body
+
+  s3.getSignedUrl('putObject', {
+    Bucket: 'YOUR_SPACE_NAME',
+    Key: filename,
+    ContentType: contentType,
+    Expires: 5 * 60 * 1000 // 5 minutes
+  }, (err, data) => {
+    if (err) return next(err)
+
+    res.setHeader('content-type', 'application/json')
+    res.end(JSON.stringify({
+      method: 'put',
+      url: data
+    }, null, 2))
+  })
+})
+
+app.listen(8080)
+```
+
+For a working example that you can run and play around with, see the [digitalocean-spaces](https://github.com/transloadit/uppy/tree/master/examples/digitalocean-spaces) folder in the Uppy repository.
+
 ### Retrieving presign parameters of the uploaded file
 ### Retrieving presign parameters of the uploaded file
 
 
 Once the file is uploaded, it's possible to retrieve the parameters that were
 Once the file is uploaded, it's possible to retrieve the parameters that were