社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

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

Muhammed Erem • 3 年前 • 1314 次点击  

将文件上传到box时,会出现一个错误,显示文件大小小于要求。这是我的代码:

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)

我将上传多个文件作为序列,一些文件的大小可能小于2000万。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131501
 
1314 次点击  
文章 [ 1 ]  |  最新文章 3 年前
Tim Roberts
Reply   •   1 楼
Tim Roberts    3 年前

分块上传的开销更大,因此它们只允许上传大于20MB的文件。对于较小的文件,请使用普通 upload 应用程序编程接口。事实上,他们推荐正常的 上载 高达50MB。