Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save codeibrahima/bc6bf68125ffce8f45a234ad741a2685 to your computer and use it in GitHub Desktop.

Select an option

Save codeibrahima/bc6bf68125ffce8f45a234ad741a2685 to your computer and use it in GitHub Desktop.

Revisions

  1. @eliashussary eliashussary revised this gist Sep 20, 2017. 1 changed file with 17 additions and 5 deletions.
    22 changes: 17 additions & 5 deletions Node Digital Ocean Spaces.js
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,32 @@
    import AWS from 'aws-sdk';
    import AWS from 'aws-sdk'
    import Buffer from 'buffer'

    AWS.config.setPromisesDependency(require('bluebird'))

    AWS.config.setPromisesDependency(require('bluebird'));
    ;(async () => {

    const spaces = new AWS.S3({
    endpoint: new AWS.Endpoint(process.env.DO_ENDPOINT),

    // {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 = new Buffer(10) // typically and image stored as a buffer, etc.
    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,
    Key: fileKey,
    Body: fileBuffer,
    ACL: 'public-read'
    }).promise()
  2. @eliashussary eliashussary revised this gist Sep 20, 2017. 1 changed file with 18 additions and 12 deletions.
    30 changes: 18 additions & 12 deletions Node Digital Ocean Spaces.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,22 @@
    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'));
    ;(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: file.buffer,
    ACL: 'public-read'
    }).promise()
    await spaces.putObject({
    Bucket: process.env.DO_BUCKET_NAME,
    Key: fileKey,
    Body: fileBuffer,
    ACL: 'public-read'
    }).promise()

    })
  3. @eliashussary eliashussary created this gist Sep 20, 2017.
    16 changes: 16 additions & 0 deletions Node Digital Ocean Spaces.js
    Original 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()