Skip to content

Instantly share code, notes, and snippets.

@cbare
Created January 30, 2013 23:59
Show Gist options
  • Select an option

  • Save cbare/4678550 to your computer and use it in GitHub Desktop.

Select an option

Save cbare/4678550 to your computer and use it in GitHub Desktop.
Test out the new fileHandle API from python.
##
## upload a file with the synapse fileHandle service
############################################################
## import the synapse library and sign in
import synapseclient
syn = synapseclient.Synapse()
syn.login('[email protected]', 'secret')
## the file we're going to upload
filename = '/Users/chris/Documents/graphics/space_needle_fireworks.png'
headers = {'Accept': 'application/json', 'sessionToken': syn.sessionToken}
## url of fileHandle service
url = 'http://file-prod-m.prod.sagebase.org/file/v1/fileHandle'
## post to the fileHandle service to upload a file
response = requests.post(url, files={'space_needle_fireworks.png': open(filename)}, headers=headers)
## show the response
print response
# <Response [201]>
print response.json()
# {u'list': [{u'contentType': u'image/png', u'key': u'1669688/45f07407-9829-4989-8647-4c22ec0b5b72', u'createdOn': u'2013-01-30T23:17:03.000Z', u'contentMd5': u'017a79621107bed3c0876163b0889837', u'concreteType': u'org.sagebionetworks.repo.model.file.S3FileHandle', u'etag': u'58661304-02c7-46b1-8e5e-7934e3ed564f', u'bucketName': u'proddata.sagebase.org', u'createdBy': u'1669688', u'fileName': u'space_needle_fireworks.png', u'id': u'900', u'contentSize': 211588}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment