diff --git a/README.md b/README.md index 14f9d13..a77b5c7 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,5 @@ Note: You can also refer to [Awesome Minio](https://github.com/minio/awesome-min - [Setup Nginx proxy with Minio](./docs/setup-nginx-proxy-with-minio.md) - [Setup Apache HTTP proxy with Minio](./docs/setup-apache-http-proxy-with-minio.md) - [Rclone with Minio](./docs/rclone-with-minio.md) +- [Download from Browser with PreSignedGet](./docs/presigned-get-download-from-browser.md) +- [Upload via Browser with PreSignedPut](./docs/presigned-put-upload-via-browser.md) diff --git a/docs/presigned-get-download-from-browser.md b/docs/presigned-get-download-from-browser.md new file mode 100644 index 0000000..7fbb8bc --- /dev/null +++ b/docs/presigned-get-download-from-browser.md @@ -0,0 +1,73 @@ +# Using pre-signed URLs to download via the browser [](https://gitter.im/minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +Using presigned URLs, you can allow a browser to download a private file +directly from S3 without exposing your S3 credentials to the user. The +following is an annotated example of how this can be used in a Node.js +application, using [minio-js](https://github.com/minio/minio-js). + +This application will work out of the box, just copy each piece together into a +file and run it. + +### Server code + +```js +const Minio = require('minio') + +var client = new Minio({ + endPoint: 'play.minio.io', + port: 9000, + secure: true, + accessKey: 'Q3AM3UQ867SPQQA43P2F', + secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG' +}) +``` + +In order to sign the request, we need to create the Minio client and pass it +our credentials. With the client, you can download and upload files, +among [much more](https://github.com/minio/minio-js/blob/master/docs/API.md). + +These are real credentials to an example Minio server — try it out! + +```js +// express is a small HTTP server wrapper, but this works with any HTTP server +const server = require('express')() + +server.get('/presignedUrl', (req, res) => { + + client.presignedGetObject('pictures', 'house.png', (err, url) => { + if (err) throw err + + res.redirect(url) + }) + +}) + +server.listen(8080) +``` + +[`presignedGetObject`](https://docs.minio.io/docs/javascript-client-api-reference#presignedGetObject) +creates the URL we can use to download `pictures/house.png`. The link will +automatically expire after 7 days — this can be adjusted using the optional +`expiry` argument. + +In this example, the HTTP server will generate a link to download an image of +a house from S3. It will then redirect the user to that link. + +### Client code +You can also use client-side JavaScript to request the file from the server. +Using [jQuery](http://jquery.com/), here is an example of this in action. It +will insert some text from S3 into a `div`. + +```html +
+ + + +``` diff --git a/docs/presigned-put-upload-via-browser.md b/docs/presigned-put-upload-via-browser.md new file mode 100644 index 0000000..a730f17 --- /dev/null +++ b/docs/presigned-put-upload-via-browser.md @@ -0,0 +1,107 @@ +# Upload files from browser using pre-signed URLs [](https://gitter.im/minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +Using presigned URLs, you can allow a browser to upload a file +directly to S3 without exposing your S3 credentials to the user. The following +is an annotated example of this using [minio-js](https://github.com/minio/minio-js). + +### Server code + +```js +const Minio = require('minio') + +var client = new Minio({ + endPoint: 'play.minio.io', + port: 9000, + secure: true, + accessKey: 'Q3AM3UQ867SPQQA43P2F', + secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG' +}) +``` + +Here, we create a new Minio client, which is necessary in order to presign +an upload URL. + +Those are real Minio server credentials — try them out! + +```js +// express is a small HTTP server wrapper, but this works with any HTTP server +const server = require('express')() +// uuid.v4() generates a unique identifier for each upload +const uuid = require('node-uuid') + +server.get('/presignedUrl', (req, res) => { + + client.presignedPutObject('uploads', uuid.v4(), (err, url) => { + if (err) throw err + + res.end(url) + }) + +}) + +server.listen(8080) +``` + +Here are the docs for [`presignedPutObject`](https://docs.minio.io/docs/javascript-client-api-reference#presignedPutObject). + +When a user visits the server, it will respond with a URL that can be used to +upload a file to S3. Then, using AJAX requests, you can upload a file +straight from the browser. + +### Client code + +This application uses [jQuery](http://jquery.com/). + +On the browser, we want to allow the user to select a file for upload, then, +after retrieving an upload URL from the Node.js server, the user can upload it +straight to S3. + +```html + + + +