Skip to content

Instantly share code, notes, and snippets.

@trolleway
Created December 5, 2016 13:36
Show Gist options
  • Save trolleway/4e0247288d416d1abbda03b02bc787a5 to your computer and use it in GitHub Desktop.
Save trolleway/4e0247288d416d1abbda03b02bc787a5 to your computer and use it in GitHub Desktop.
import requests
import urllib2
ngw_root = 'http://trolleway.nextgis.com'
ngw_creds = ('', '')
headers = {'Content-type': 'application/x-www-form-urlencoded'}
payload = {'file':urllib2.urlopen('http://trolleway.nextgis.com/api/resource/826/feature/5/attachment/37/image'),'name':'filename.jpg'}
print 'Upload attachment to ' + ngw_root + '/api/component/file_upload/upload'
req = requests.post(ngw_root + '/api/component/file_upload/upload', data=payload, auth=ngw_creds, headers=headers)
print req.status_code
print req.text
@BishopGIS
Copy link

Вот так работает
with closing(requests.get(url_src + str(item['id']) + '/attachment/' + str(attachment_id) + '/download', auth=creds_src, stream=True)) as f:
req = requests.put(url_dst + '/component/file_upload/upload', data=f, auth=creds_dst)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment