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