Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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
[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.)?
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 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.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!