cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Check out the Dropbox cheat sheet for getting started in 2021 here!

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dropbox v2 upload cursor offset confusion

Dropbox v2 upload cursor offset confusion

Explorer | Level 4
I can only upload the first chunk only

import dropbox,requests,sys
def down(url:disappointed face:
dbx=dropbox.Dropbox(AccessToken)

size=25*1024*1024
a=0
i=0

params = {'':'', 'render':'download'}

r=requests.get(url,params=params,stream=True)
clen=r.headers['Content-length']

for chunk in r.iter_content(chunk_size=size:disappointed face:

if chunk:
i+=1
a+=len(chunk)

c=a/(1024*1024)
sys.stdout.write('\r'+str(round(c,2)))
if i==1:
strtid = dbx.files_upload_session_start(chunk)
cursor = dropbox.files.UploadSessionCursor(session_id=strtid.session_id,offset=a)
commit = dropbox.files.CommitInfo(path='/source')
if (clen-a)<size:
dbx.files_upload_session_finish(chunk,cursor,commit)

else:
dbx.files_upload_session_append(chunk,cursor.session_id,cursor.offset)


url='https:confused face:/downloads.sourceforge.net/project/openofficeorg.mirror/extended/iso/en/OOo_3.3.0_Win_x86_insta...'
down(url)


And I got a error

>Traceback (most recent call last:disappointed face:
> File "/home/google2drive/mysite/templates/u.py", line 38, in <module>
> down(url)
> File "/home/google2drive/mysite/templates/u.py", line 32, in down
> dbx.files_upload_session_append(chunk,cursor.session_id,cursor.offset)
> File "/home/google2drive/.local/lib/python3.6/site-packages/dropbox/base.py", line 2242, in files_upload_session_append
> f,
> File "/home/google2drive/.local/lib/python3.6/site-packages/dropbox/dropbox.py", line 296, in request
> user_message_locale)
>dropbox.exceptions.ApiError: >ApiError('0e6a9a0abf5e491efe40d71e4c6cdb76', >UploadSessionLookupError('incorrect_offset', >UploadSessionOffsetError(correct_offset=52428800)))
2 Accepted Solutions

Accepted Solutions

Re: Dropbox v2 upload cursor offset confusion

Dropboxer

[Cross-linking for reference: https:confused face:/stackoverflow.com/questions/51606801/python3-dropbox-uploading-error-using-api-v2 ]

 

That error indicates that you're supplying an incorrect offset value for this upload session when uploading a chunk of data. The error includes the correct value, but you'll need to debug your code to see why you're not sending it in the first place. (I don't see where you update the offset value in your code, for example.)

 

There's a basic example of using upload sessions with the Python SDK here:

 

https:confused face:/stackoverflow.com/a/43724479/1305693

View solution in original post

Re: Dropbox v2 upload cursor offset confusion

Dropboxer

A 'path/conflict/file' error indicates that the upload failed because there is already a file at the specified path.

 

You should instead specify a different path, or supply a different WriteMode to to files_upload_session_finish in the CommitInfo to automatically handle the conflict.

 

View solution in original post

8 Replies 8

Re: Dropbox v2 upload cursor offset confusion

Dropboxer

[Cross-linking for reference: https:confused face:/stackoverflow.com/questions/51606801/python3-dropbox-uploading-error-using-api-v2 ]

 

That error indicates that you're supplying an incorrect offset value for this upload session when uploading a chunk of data. The error includes the correct value, but you'll need to debug your code to see why you're not sending it in the first place. (I don't see where you update the offset value in your code, for example.)

 

There's a basic example of using upload sessions with the Python SDK here:

 

https:confused face:/stackoverflow.com/a/43724479/1305693

View solution in original post

Re: Dropbox v2 upload cursor offset confusion

Explorer | Level 4
I have the variable `a` for offset.
Now i'm getting UploadSessionError('path',WriteError('conflict',WriteConflictError('file',None))))

Re: Dropbox v2 upload cursor offset confusion

Dropboxer

A 'path/conflict/file' error indicates that the upload failed because there is already a file at the specified path.

 

You should instead specify a different path, or supply a different WriteMode to to files_upload_session_finish in the CommitInfo to automatically handle the conflict.

 

View solution in original post

Re: Dropbox v2 upload cursor offset confusion

Explorer | Level 4
thanks Now the problem is the offset of files_upload_session_finish , I am using the content length for the offset but it is giving error

Code:

import dropbox,requests,sys
def down(url:disappointed face:

dbx=dropbox.Dropbox(AccessToken)

size=45*1024
a=0
i=0
p=0
params = {'':'', 'render':'download'}
r=requests.get(url,params=params,stream=True)
clen=r.headers['Content-length']

for chunk in r.iter_content(chunk_size=size:disappointed face:

if chunk:
i+=1
a+=len(chunk)
c=a/(1024)
print('\n'+str(c)+' of '+str(clen))
if i==1:
strtid = dbx.files_upload_session_start(chunk)
cursor = dropbox.files.UploadSessionCursor(session_id=strtid.session_id,offset=len(chunk))
commit = dropbox.files.CommitInfo(path='/sourttt',mode=dropbox.files.WriteMode('add'))
if ((int(clen)-p))<=size:
cur=dropbox.files.UploadSessionCursor(session_id=strtid.session_id,offset=int(a))
dbx.files_upload_session_finish(chunk,cur,commit)


else:
dbx.files_upload_session_append(chunk,cursor.session_id,a)
p=a

url='https:confused face:/speedtest.ftp.otenet.gr/files/test100k.db'
down(url)

Error:

dropbox.exceptions.ApiError: ('281cb346aa41adc8436f415fc4d0de0a', UploadSessionFinishError('lookup_failed', UploadSessionLookupError('incorrect_offset', UploadSessionOffsetError(correct_offset=138240))))

The content length is 100Kb(102400) but the error showing me the correct offset is 138240 and the difference between those are 35Kb . What should I do for offset value in files_upload_session_finish
?

Re: Dropbox v2 upload cursor offset confusion

Dropboxer
The offset value works the same way for files_upload_session_finish as it does for the other calls. It should match how much data you've uploaded in the upload session so far.

It sounds like you may have a bug where you're uploading more data than expected. I recommend adding extra logging or working through your code in a debugger to determine where the discrepancy is taking place.

Re: Dropbox v2 upload cursor offset confusion

Explorer | Level 4
At the first initialisation for cursor the offset value is 45kb. And I am trying to upload 100kb file .so after 2 iterations uploaded data is 90kb and on finishing I have set the cursor.offset to total size of the file that is 100kb ,but it is returning error saying the correct offset is 135kb .45+45+45=135kb , on third iteration which is last it is showing that it needs the correct offset is 135kb but the original file length is only 100kb. So what am I missing?

Re: Dropbox v2 upload cursor offset confusion

Explorer | Level 4
Updated my code still the same,How can I preformat my code so the code could be more understanding like in stackoverflow we could use 4 blank space .?

import dropbox,requests

d=dropbox.Dropbox(AccesToken)
t=0
f=True
clos=False
r=requests.get('https:confused face:/www.sample-videos.com/text/Sample-text-file-10kb.txt',stream=True)
c=r.headers['Content-length']
for a in r.iter_content(chunk_size=4*1024:disappointed face:
if f:
t+=len(a)
start=d.files_upload_session_start(a)
cursor=dropbox.files.UploadSessionCursor(session_id=start.session_id,offset=len(a))

commit=dropbox.files.CommitInfo('/as',mode=dropbox.files.WriteMode('add'))
f=False
else :
if (int(c)-t)&lt;=(4*1024:disappointed face:

clos=True

d.files_upload_session_append_v2(a,cursor,close=clos)

Re: Dropbox v2 upload cursor offset confusion

Dropboxer
Can you add extra logging or work through your code in a debugger to determine where the discrepancy is taking place?

By the way, if you use the "Reply" option (not "Quick Reply), the forum's "Rich Text" editor has a code button you can use to get code formatting. The button has a label like "</>".
Polls
Are you starting new work habits this year?

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?