使用 python 将视频上传到保管箱的简单代码

Simple code to upload a video to dropbox with python

我一直致力于编写简单的代码,使用 python 将文件夹中的最新视频上传到 Dropbox。我几乎让它工作了,但是 运行 遇到了两个问题。最大的问题是视频显示在 Dropbox 上时无法播放,我相信文件在上传时已损坏。另一个问题是文件名被重命名,我想保留文件名,因为我在名称中添加了时间戳,以便在拍摄视频时轻松记录。 -谢谢

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)

我不知道您要上传的视频的大小,但给定了 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)。

至于文件在到达 Dropbox 时被重命名,问题出在您的 dropbox_path 定义上。当您调用 files_upload() 时,f.read() 参数只是要上传的原始数据; dropbox_path arg 是预期文件名的唯一指示。您需要在 dropbox_path 定义中包含 newestfile(不过,如果您使用 Windows,请小心:os.path.join 使用 \ 加入路径,与 Dropbox 不兼容)。