I'm uploading files to S3 using aws-sdk module. I use uuid to represent each file.
My question is - how can I set the real file name(which is not the uuid), so when I download the key from S3 later - the file that will be downloaded will be named as the real file name?
I've read about Content-Disposition header but I think this is only in download request and I want to do this on upload request
current code is:
var s3obj = new AWS.S3({
params: {
Bucket: CONFIG.S3_BUCKET,
Key: key,
ContentType: type
}
});
s3obj.upload({
Body: fileData
}).on('httpUploadProgress', function(evt) {
logger.debug('storing on S3: %s', evt);
}).send(function(err, data) {
logger.debug('storing on S3: err: %s data: %s', err, data);
return callback();
});
Thanks!
As Frederic has suggested
Content-Disposition
header will do the job. However, I'd strongly suggest to use a library for building this header (as it will spare you a lot of trouble when handling different platforms supporting different standards and the biggest problem - ENCODING!There's a great library to achieve it and it's called
content-disposition
. Simple usage could be as follows:Content-Disposition
is indeed available when uploading your file to s3 (http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#upload-property). You can then add the filename thereI have the similar requirement that I need to upload file with lowercase file name no matter what file name the user uploads. I tried ContentDisposition but somehow it didn't work so I tried the below configuration and it worked for me.
In short, make sure your Key reflect the name you would like the file to be.