Created
October 24, 2019 08:47
-
-
Save sinpaout/117c02f8ad3fe62795885acc9002a2bc to your computer and use it in GitHub Desktop.
Sample for digital ocean spaces spaces uploading
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 characters
const fs = require('fs') | |
const uuidv4 = require('uuid/v4') | |
const AWS = require('aws-sdk'); | |
AWS.config.update({ | |
accessKeyId: 'aaaabbbb', | |
secretAccessKey: 'aaabbbccc', | |
}); | |
const spacesEndpoint = new AWS.Endpoint('nyc1.digitaloceanspaces.com'); | |
const s3 = new AWS.S3({endpoint: spacesEndpoint}); | |
const file = fs.readFileSync('path/to/file') | |
const key = uuidv4() | |
const params = { | |
ContentType: 'image/png', | |
ACL: 'public-read', | |
Bucket: 'user-images/aaa', | |
Body: file, | |
Key: `${key}.png`, | |
} | |
s3.putObject(params, function(err, result) { | |
if (err) { | |
throw err | |
} | |
console.log('result', result); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment