0

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)
2
  • Hi, welcome to Stack Overflow. Can you tell me what the symbol dbx is? I'm assuming it's some object created by some python dropbox binding. Obviously omit your API keys, but I would like to be sure. Commented Feb 3, 2018 at 17:36
  • [Cross-linking for reference: dropboxforum.com/t5/API-support/… ] Commented Feb 5, 2018 at 16:01

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

5 Comments

I am still learning python and am having a hard time understanding the documentation, is there anything you would recommend to help me figure out what is being said there?
@kwjamesblond It's not just you; that documentation is...not straightforward. Check out the link below for code that worked for me (via Python 3.6). Basically, you start a session, sequentially upload chunks of your file (the 150MB-per-upload still applies, so I have it set to append <150MB chunks), then finish the session with the last of your data and a path to save the file. dropbox.com/s/aljw1ppv80ywm0l/…
Hello I am still having the same issue with the code example you provided, I noticed there is no .h264 at the end of this file in Dropbox it just says binary when looking at this file. Could this be the issue? Also I had to lower the chunk_size to get the program to run properly. I am using a Raspberry Pi 3 with Raspbian so this may factor in.
@kwjamesblond Yep, I think that's the issue. I didn't include the changes to the dropbox_path definition I noted in my answer. You'll want to redefine this to dropbox_path = os.path.join('/',newestfile) (also I think the asterisk could be confusing to Dropbox). Oh nice...yeah I imagine you'll want to let Dropbox handle a bunch of small appends since you're on a Pi.
Thanks I was able to get the original code and the one you commented with to work now, thanks a lot for the great help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.