1

I'm using the node-s3-client library to upload files to my bucket.

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.

2
  • 1
    Have you tried using a loop to get all files in folder and concatenate file name at Key? Commented Feb 1, 2017 at 17:13
  • I'd prefer I didn't have to resort to that, but great idea nonetheless. I'll do that for now. Commented Feb 1, 2017 at 18:10

1 Answer 1

3

Use Prefix instead of Key:

const params = {
  localDir: './build',
  s3Params: {
    Bucket: config.aws.s3Bucket,
    Prefix: 'Library/'
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.