Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用SDK将大型文件上载到OneDrive_Python_Onedrive - Fatal编程技术网

Python 使用SDK将大型文件上载到OneDrive

Python 使用SDK将大型文件上载到OneDrive,python,onedrive,Python,Onedrive,我想上传一个巨大的(大于2GB)文件到OneDrive 我已经尝试使用sdk网页()中的代码 虽然代码适用于较小的文件,但在上载大文件时,我得到: 断管错误:[Errno 32]断管 requests.exceptions.ConnectionError:('Connection aborted',BrokenPipeError(32,'breaked pipe'))SDK现在不推荐使用。 您可以使用Microsoft graph和OneDriveAPI将文件上载到OneDrive OneDri

我想上传一个巨大的(大于2GB)文件到OneDrive

我已经尝试使用sdk网页()中的代码

虽然代码适用于较小的文件,但在上载大文件时,我得到:

断管错误:[Errno 32]断管

requests.exceptions.ConnectionError:('Connection aborted',BrokenPipeError(32,'breaked pipe'))

SDK现在不推荐使用。 您可以使用Microsoft graph和OneDriveAPI将文件上载到OneDrive
OneDriveAPI支持小文件的简单上载(您是否尝试过此操作?错误是否持续发生(在大文件上)或再次启动上载是否足够?手动上载相同的文件是否有效(持续)?非常感谢。我在上载命令末尾添加了“.to_dict()”,这解决了问题。
returned_item = client.item(drive='me', path=backupPath).children['photos.tgz'].upload_async('/Users/koot/photos.tgz')
#Creating an upload session
        upload_session = requests.post(onedrive_destination+"/"+file_name+":/createUploadSession", headers=headers).json()

        with open(file_path, 'rb') as f:
            total_file_size = os.path.getsize(file_path)
            chunk_size = 327680
            chunk_number = total_file_size//chunk_size
            chunk_leftover = total_file_size - chunk_size * chunk_number
            i = 0
            while True:
                chunk_data = f.read(chunk_size)
                start_index = i*chunk_size
                end_index = start_index + chunk_size
                #If end of file, break
                if not chunk_data:
                    break
                if i == chunk_number:
                    end_index = start_index + chunk_leftover
                #Setting the header with the appropriate chunk data location in the file
                headers = {'Content-Length':'{}'.format(chunk_size),'Content-Range':'bytes {}-{}/{}'.format(start_index, end_index-1, total_file_size)}
                #Upload one chunk at a time
                chunk_data_upload = requests.put(upload_session['uploadUrl'], data=chunk_data, headers=headers)
                print(chunk_data_upload)
                print(chunk_data_upload.json())
                i = i + 1