andrewrk / node-s3-client

high level amazon s3 client for node.js
MIT License
1k stars 303 forks source link

Upload directory into *folder* within bucket #160

Open Robinnnnn opened 7 years ago

Robinnnnn commented 7 years ago

I have a local folder, /build, that I would like to upload to a folder within an S3 bucket, entitled Library.

Placing individual files into the Library folder is easy:

const params = {
  localFile: './individualFile',
  s3Params: {
    Bucket: config.aws.s3Bucket,
    Key: 'Library/individualFile',
  }
}

const uploader = client.uploadFile(params); // works great!

However, I'm not sure how to configure the params to upload the contents of a directory into a folder within a bucket. I've tried this:

const params = {
  localDir: './build',
  s3Params: {
    Bucket: config.aws.s3Bucket,
    Key: 'Library/',
  }
}

const uploader = client.uploadDir(params); // doesn't work :(

The upload is successful, but the contents end up at the root of the bucket rather than inside the folder. In other words, the Key feature doesn't seem to work when it comes to directories.

RoosterKelly commented 7 years ago
s3Params: {
    Bucket: "config.aws.s3Bucket",
    Prefix: "Library",
    // other options supported by putObject, except Body and ContentLength. 
    // See: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property 
}