Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- url = 'https://www.googleapis.com/upload/storage/v1/b/my-bucket/o?alt=json&name=test-file2&uploadType=resumable'
- auth = ('Authorization',
- 'Bearer ya29.....g')
- resp = requests.post(url, headers=dict([auth, ('X-Upload-Content-Type', 'text/plain')]))
- assert resp.status_code == 200
- url = resp.headers['location']
- # Note using bytes */* in content range
- resp = requests.post(url, headers=dict([auth, ('Content-Range', 'bytes */*')]))
- assert resp.status_code == 308
- # send first full 256K chunk, still without specifying full content length
- resp = requests.post(url, headers=dict([auth, ('Content-Range', 'bytes 0-262143/*'), ('Content-Type', 'text/plain')]), data='A' * 262144)
- assert resp.status_code == 308
- # Just for fun let's ask where we are in the upload. Still not specifying full content length.
- resp = requests.post(url, headers=dict([auth, ('Content-Range', 'bytes */*')]))
- assert resp.status_code == 308
- assert resp.headers['range'] == 'bytes=0-262143'
- # upload final chunk of 10 bytes, and specify full content length for the first time
- resp = requests.post(url, headers=dict([auth, ('Content-Range', 'bytes 262144-262153/262154'), ('Content-Type', 'text/plain')]), data='A' * 10)
- assert resp.status_code == 200
- assert resp.json()['size'] == '262154'
- print 'Grandi successi!!!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement