文件大小 5622620 小于此 API: ''20000000', Python Box-SDK 允许的最小值

File size 5622620 less than minimum allowed for this API: ''20000000', Python Box-SDK

将文件上传到盒子时出现错误,提示文件大小小于要求。这是我的代码:

import os
from boxsdk import JWTAuth, Client
import schedule
import time

directory = '/videos'


def save_video():
    retval = os.getcwd()
    help = (retval)
    os.chdir(help + directory)
    retval = os.getcwd()

    config = JWTAuth.from_settings_file('box_config.json')
    client = Client(config)

    for file_name in os.listdir(retval):
        print(file_name)
        if file_name == 'box_config.json':
            continue
        file_size = os.path.getsize(file_name)
        print(file_name)
        folder_id = '144613233618'

        upload_session = client.folder(folder_id=folder_id).create_upload_session(file_size, file_name)
        print('Created upload session {0} with chunk size of {1} bytes'.format(upload_session.id, upload_session.part_size))

        chunked_upload = upload_session.get_chunked_uploader(file_name)
        uploaded_file = chunked_upload.start()
        print('File "{0}" uploaded to Box with file ID {1}'.format(uploaded_file.name, uploaded_file.id))

        os.remove(file_name)



schedule.every().day.at("11:34").do(save_video)

while True:
    schedule.run_pending()
    time.sleep(1)

我会按顺序上传多个文件,有些文件的大小可能小于 20000000。

分块上传有更多的开销,所以他们只允许大于 20MB 的文件。对于较小的文件,使用正常的 upload API。事实上,他们建议正常 upload 最多 50MB。