cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Upload PDF files/proper encoding

Upload PDF files/proper encoding

kaistullich
New member | Level 2

I have a simple Python Flask application that allows users to upload PDF files to a Dropbox account. I am able to successfully upload the file to Dropbox, as well as go directly go to dropbox.com and download the file. But when I try to open the file I just downloaded from dropbox.com directly it mentions that the file is corrupted/not correctly encoded.

 

I am new to file uploads in general, what is the best practice to encoding PDF files and storing them on Dropbox?

 

This is the code I use to upload the PDF files:

 

    def upload_to_dbx(self):
        # read in the file as binary
        with open(os.path.join('uploaded_forms', self.uploaded_filename), 'rb') as f:
            read_file = f.read()

        # path wher the uploaded file will be stored in Dropbox
        user_filepath_name = '/{fname} {lname}/{filename}'.format(fname=self.user.first_name,
                                                                  lname=self.user.last_name,
                                                                  filename=self.uploaded_filename
                                                                  )
        # upload the file with the specified file path
        try:
            self.dbx.files_upload(read_file, '{path}'.format(path=user_filepath_name))
            return self.uploaded_filename
        except dropbox.files.UploadError as e:
            return e 

 

4 Replies 4

Greg-DB
Dropbox Staff

[Cross-linking for reference: https://stackoverflow.com/questions/48970161/pdf-encoding-to-upload-to-dropbox-api ]

 

Using `open`, `read`, and `files_upload` is the right way to upload files like this. The Dropbox API will just accept whatever data you send it. 

 

I just tried this and it's working properly for me. I can upload a local PDF file and the resulting uploaded file is viewable on the web site. Can you check that you're storing and retrieving the correct data at each step leading up to that `files_upload` call in your code (e.g., in your `save` method, etc.)?

kaistullich
New member | Level 2

Hi Greg,

 

Thank you for your reply.  I have just realized that the issue is not with my code, but rather with the PDF file itself. The PDF file that I was trying to upload has "interactive fields" a user has to fill out in Adobe Reader. For some reason Dropbox does not like that, this is something I will have to look into.

 

Other PDF files that do not have interactive fields work just fine with uploading and I can view them on Dropbox files.

Psome
New member | Level 2
Any update on this situation. I am having a similar problem. Unfortunately, in my senecio i can not controll the source of the PDF. Is there a way to not get a corroupted off out of the api the the same file is fine out of the web UI?

Greg-DB
Dropbox Staff

@Psome When downloading a file from the Dropbox API, it will just return whatever raw data was uploaded. 

Since in your case the file is displaying in the Dropbox web UI, it sounds like the issue you're seeing may be slightly different than the original issue in this thread. I'll follow up with you privately to see if we can help troubleshoot this.

Need more support?