You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
kaistullich
7 years agoNew member | Level 2
Upload PDF files/proper encoding
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
- Greg-DBDropbox 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.)?
- kaistullichNew 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.
- PsomeNew member | Level 2Any 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?
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,915 PostsLatest Activity: 2 hours agoIf you need more help you can view your support options (expected response time for an email or 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!