How come AWS S3 is erasing my extension from PDF files

+4 votes

In my current app, I've successfully been able to upload PDFs to my storage. The problem is, when I download the file, it doesn't have an extension and cannot be opened. I have to add .pdf to the end of the file for it to be recognized (and it does open the correct file).

However in my app, my file already has a .pdf extension, and I know is uploading properly because I'm able to download and open.

Here is my code please help:

 { fieldname: ‘files’,
  originalname: ‘tsunami_zone_e_final.pdf’,
  encoding: ‘7bit’,
  mimetype: ‘application/pdf’,
  size: 2310366,
  bucket: ‘company-name-dev’,
  key: ‘123456789999’,
  acl: ‘public-read’,
  contentType: ‘application/octet-stream’,
  contentDisposition: null,
  storageClass: ‘STANDARD’,
  serverSideEncryption: null,
  metadata: [Object],
  location: ‘https://company-name.s3.us-west-2.amazonaws.com/1521233750192',
  etag: ‘“12345etag12345etag12345”’ } ] }

Mar 27, 2018 in Cloud Computing by brat_1
• 7,200 points
4,002 views

2 answers to this question.

+1 vote
Best answer

I think the problem should be with your content-header. Be assured, you write it in the correct format.

You will also have to specify Content-Disposition to make sure your file is downloaded in the same originalname property value.

Below is the code with Nodejs S3 SDK:

var params = {
  Body: <Binary String>, 
  Bucket: "youbucket", 
  Key: "1521233750192", 
  ContentDisposition: 'attachment; filename="tsunami_zone_e_final.pdf";', // from `originalname`
  ContentType: 'application/pdf', // from `mimetype`
 };

 s3.putObject(params, function(err, data) {
   if (err) console.log(err, err.stack); // an error occurred
   else     console.log(data);           // successful response
 });

answered Mar 27, 2018 by code_ninja
• 6,300 points

selected Oct 11, 2018 by Omkar
+1 vote
I am not sure what language/framework you are using but you should make sure to pass the correct Content-Type header. You will also need Content-Disposition header to make sure your file is downloaded with the same originalname property value. And once most browsers will allow for inline display of pdfs, you may also want to force the download (also using Content-Disposition).
answered Oct 11, 2018 by findingbugs
• 4,780 points

Related Questions In Cloud Computing

0 votes
1 answer

How to delete the files from AWS S3 except the recently 5 added/updated files?

Use AWS s3 rm command with multiple --exclude options as shown: aws ...READ MORE

answered Jul 30, 2018 in Cloud Computing by Gopalan
• 1,360 points
3,864 views
0 votes
1 answer

Is there a way to transfer files between AWS s3 and ec2

The answer is a definite yes yes. ...READ MORE

answered Apr 17, 2018 in Cloud Computing by brat_1
• 7,200 points
884 views
0 votes
1 answer

AWS: Is there a way I can edit files in S3 right away in the browser?

There is not currently an AWS-supported method ...READ MORE

answered Jun 19, 2018 in Cloud Computing by Meci Matt
• 9,460 points
5,205 views
+8 votes
3 answers

How to download folder from AWS S3?

To Download using AWS S3 CLI : aws ...READ MORE

answered Sep 7, 2018 in Cloud Computing by eatcodesleeprepeat
• 4,710 points
289,027 views
0 votes
1 answer

How is AWS DynamoDB different from other AWS Databases?

Hi vishal, Amazon DynamoDB is a nonrelational database ...READ MORE

answered Oct 30, 2018 in Cloud Computing by remo12
690 views
+4 votes
2 answers

Amazon S3 Permission problem - How to set permissions for all files at once?

This can be done by setting the ...READ MORE

answered Mar 27, 2018 in Cloud Computing by brat_1
• 7,200 points
4,067 views
+2 votes
3 answers

AWS S3 copy files and folders between two buckets

A simplified example using the aws-sdk gem: AWS.config(:access_key_id ...READ MORE

answered Aug 16, 2018 in Cloud Computing by Priyaj
• 58,020 points
4,785 views
+2 votes
2 answers

Is there a way to add cache control in AWS S3?

use of  current upstream master branch will ...READ MORE

answered Apr 10, 2018 in Cloud Computing by hemant
• 5,790 points
8,666 views
+1 vote
3 answers

How to upload files on aws elastic beanstalk?

yes once you store it in (AWS) ...READ MORE

answered Sep 3, 2018 in Cloud Computing by bug_seeker
• 15,510 points
6,832 views
0 votes
2 answers

Is there a way to copy AMI from one AWS account to another AWS account using boto?

You could share the AMI from one ...READ MORE

answered Aug 21, 2018 in Cloud Computing by Priyaj
• 58,020 points
2,256 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP