I have been working at writing simple code to upload the newest video in a folder to Dropbox with python. I almost got it working but am running into two issues. The big issue is while the video shows up on Dropbox it cannot be played and I believe the file is corrupted when uploaded. The other issue is that the filename is renamed which I would like to keep the filename because I added a timestamp to the name to easily record when the video was taken. -Thanks
dbx.dropbox.Dropbox('EmptyKey')
allfiles = glob.glob('/home/pi/Documents/CameraFeeds/*.h264')
newestfile = max(allfiles, key=os.path.getctime)
dropbox_path = os.path.join('/*')
with open(newestfile, 'rb') as f:
dbx.files_upload(f.read(), dropbox_path, mute=True)
I don't know the size of the videos you're trying to upload, but given a simple calculation of filesize for video length, it seems like you may be running into the 150MB-per-upload limit using just dbx.files_upload()
. I think you'll have better results with the files_upload_session_start()
, files_upload_session_append_v2()
, and files_upload_session_finish()
commands (found here).
As for the file being renamed when it gets to Dropbox, the issue is with your dropbox_path
definition. When you call files_upload()
, the f.read()
argument is just the raw data to upload; the dropbox_path
arg is the only indication of the expected filename. You'll need to include newestfile
in your dropbox_path
definition (be careful, though, if you're using Windows: os.path.join
uses \\
to join the paths, which isn't compatible with Dropbox).