While uploading files to box it gives an error says File size is less than required. Here is my code:
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)
I will upload more than one file as sequence and some file's size could be less than 20000000.
CodePudding user response:
Chunked uploads have more overhead, so they only allow it for files larger than 20MB. For smaller files, use the normal upload
API. In fact, they recommend the normal upload
up to 50MB.