-
-
Save codeibrahima/bc6bf68125ffce8f45a234ad741a2685 to your computer and use it in GitHub Desktop.
Revisions
-
eliashussary revised this gist
Sep 20, 2017 . 1 changed file with 17 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,32 @@ import AWS from 'aws-sdk' import Buffer from 'buffer' AWS.config.setPromisesDependency(require('bluebird')) ;(async () => { const spaces = new AWS.S3({ // {region}.digitaloceanspaces.com ex: nyc3.digitaloceanspaces.com endpoint: new AWS.Endpoint(process.env.DO_ENDPOINT), // generate here: // https://cloud.digitalocean.com/settings/api/ accessKeyId: process.env.DO_ACCESS_KEY, secretAccessKey: process.env.DO_SECRET_KEY, }) const fileKey = 'my-file-name' const fileBuffer = Buffer.from('This is a test') // typically and image or file buffer. await spaces.putObject({ // if you haven't already created one, you can do so here: https://cloud.digitalocean.com/spaces // alternative programatically by calling the following before putObject: // spaces.createBucket({bucket:'my-bucket-name'}) Bucket: process.env.DO_BUCKET_NAME, Key: fileKey, Body: fileBuffer, ACL: 'public-read' }).promise() -
eliashussary revised this gist
Sep 20, 2017 . 1 changed file with 18 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,22 @@ import AWS from 'aws-sdk'; AWS.config.setPromisesDependency(require('bluebird')); ;(async () => { const spaces = new AWS.S3({ endpoint: new AWS.Endpoint(process.env.DO_ENDPOINT), accessKeyId: process.env.DO_ACCESS_KEY, secretAccessKey: process.env.DO_SECRET_KEY, }) const fileKey = 'my-file-name' const fileBuffer = new Buffer(10) // typically and image stored as a buffer, etc. await spaces.putObject({ Bucket: process.env.DO_BUCKET_NAME, Key: fileKey, Body: fileBuffer, ACL: 'public-read' }).promise() }) -
eliashussary created this gist
Sep 20, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import AWS from 'aws-sdk'; const spaces = new AWS.S3({ endpoint: new AWS.Endpoint(process.env.DO_ENDPOINT), accessKeyId: process.env.DO_ACCESS_KEY, secretAccessKey: process.env.DO_SECRET_KEY, }) AWS.config.setPromisesDependency(require('bluebird')); await spaces.putObject({ Bucket: process.env.DO_BUCKET_NAME, Key: fileKey, Body: file.buffer, ACL: 'public-read' }).promise()