Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 将文件上载到dropbox时的进度条 导入dropbox client=dropbox.client.dropbox客户端(“”) f=打开('/ssd scratch/abhishekb/try/1.mat','rb') response=client.put_文件('/data/1.mat',f)_Python_Python 2.7_Progress Bar_Dropbox_Dropbox Api - Fatal编程技术网

Python 将文件上载到dropbox时的进度条 导入dropbox client=dropbox.client.dropbox客户端(“”) f=打开('/ssd scratch/abhishekb/try/1.mat','rb') response=client.put_文件('/data/1.mat',f)

Python 将文件上载到dropbox时的进度条 导入dropbox client=dropbox.client.dropbox客户端(“”) f=打开('/ssd scratch/abhishekb/try/1.mat','rb') response=client.put_文件('/data/1.mat',f),python,python-2.7,progress-bar,dropbox,dropbox-api,Python,Python 2.7,Progress Bar,Dropbox,Dropbox Api,我想上传一个大文件到dropbox。如何检查进度 编辑: 上传者的报价在下面是相同的。我做错了什么 import dropbox client = dropbox.client.DropboxClient('<token>') f = open('/ssd-scratch/abhishekb/try/1.mat', 'rb') response = client.put_file('/data/1.mat', f) 导入操作系统、pdb、dropbox 尺寸=1194304 cli

我想上传一个大文件到dropbox。如何检查进度

编辑: 上传者的报价在下面是相同的。我做错了什么

import dropbox
client = dropbox.client.DropboxClient('<token>')
f = open('/ssd-scratch/abhishekb/try/1.mat', 'rb')
response = client.put_file('/data/1.mat', f)
导入操作系统、pdb、dropbox
尺寸=1194304
client=dropbox.client.dropbox客户端(令牌)
path='D:/bci_代码/数据集/1.mat'
tot_size=os.path.getsize(path)
bigFile=open(路径“rb”)
uploader=client.get\u chunked\u uploader(大文件,大小)
打印“上传:”,总尺寸
uploader.offset
编辑2:

import os,pdb,dropbox
size=1194304
client = dropbox.client.DropboxClient(token)
path='D:/bci_code/datasets/1.mat'

tot_size = os.path.getsize(path)
bigFile = open(path, 'rb')

uploader = client.get_chunked_uploader(bigFile, size)
print "uploading: ", tot_size
while uploader.offset < tot_size:
    try:
        upload = uploader.upload_chunked()
        print uploader.offset
    except rest.ErrorResponse, e:
        print("something went wrong")
size=1194304
tot_size=os.path.getsize(path)
bigFile=open(路径“rb”)
uploader=client.get\u chunked\u uploader(大文件,总大小)
打印“上传:”,总尺寸
uploader.offset
上传分块
,注意:

从该
ChunkedUploader
文件\u obj
分块上传数据,直到 发生错误。发生错误时引发异常,并且可以 再次呼叫以恢复上载

因此,是的,它在返回之前上载整个文件(除非发生错误)

如果你想一次上传一个区块,你应该使用和

下面是一些工作代码,向您展示了如何一次上载一个块并在块之间打印进度:

size=1194304
tot_size = os.path.getsize(path)
bigFile = open(path, 'rb')

uploader = client.get_chunked_uploader(bigFile, tot_size)
print "uploading: ", tot_size
while uploader.offset < tot_size:
    try:
        upload = uploader.upload_chunked(chunk_size=size)
        print uploader.offset
    except rest.ErrorResponse, e:
        print("something went wrong")
从io导入字节io
导入操作系统
从dropbox.client导入dropbox客户端
client=DropboxClient(访问令牌)
路径='test.data'
块大小=1024*1024#1MB
total_size=os.path.getsize(path)
上传\u id=None
偏移量=0
打开(路径“rb”)作为f:
当偏移量<总尺寸时:
偏移量,upload\u id=client.upload\u块(
字节(f.read(块大小)),
偏移量=偏移量,上载id=上载id)
打印('目前已上载:{}字节'。格式(偏移量))
#注意下一行的“auto/”,因为
#此方法本身不附加根。
client.commit\u chunked\u upload('auto/test.data',upload\u id)
打印('上载完成')

@kevin Output:
上传:1700302131
变量
大小的含义是什么?这似乎与Kevin的tot_size有所不同,我不确定这是如何回答我的问题的。你能解释一下吗?它正在分块上传文件。我认为它定义了块的大小
tot_size
是要上载的文件的总大小。
from io import BytesIO
import os

from dropbox.client import DropboxClient

client = DropboxClient(ACCESS_TOKEN)

path = 'test.data'
chunk_size = 1024*1024 # 1MB

total_size = os.path.getsize(path)
upload_id = None
offset = 0
with open(path, 'rb') as f:
    while offset < total_size:
        offset, upload_id = client.upload_chunk(
            BytesIO(f.read(chunk_size)),
            offset=offset, upload_id=upload_id)

        print('Uploaded so far: {} bytes'.format(offset))

# Note the "auto/" on the next line, which is needed because
# this method doesn't attach the root by itself.
client.commit_chunked_upload('auto/test.data', upload_id)
print('Upload complete.')