Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js+AWS S3: Upload new file and create a new folder if doesn't exist

I am able to upload a file to AWS S3.

But, lets say I have uploaded a file to my bucket with the key: myfolder\filename.pdf,

It doesn't create the folder myfolder, and the name of the new file in S3 (also when downloaded) is myfolder_filename.pdf (it replaces backslash with underscore).

My questions are: 1. How can I determine the downloaded file's name? 2. How can I tell AWS that I want it to create new folder? maybe than the downloaded filename will be just filename.pdf.

Maybe the problem is that I used backslash and not frontslash? (i used path.join)

Thanks!

like image 269
user3343396 Avatar asked Dec 10 '25 20:12

user3343396


1 Answers

Ideally you have to send the "folder/filename" for the "Key" property in AWS sdk S3 call. S3 will create the folder if it doesn't exist based on the key you are sending.

You have to pass the key as "myfolder/filename.pdf" . The slash should be "/"

like image 145
vijilvpillai712 Avatar answered Dec 13 '25 08:12

vijilvpillai712



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!