Created
October 3, 2019 21:32
-
-
Save kdaily/d6951a5a028b51b55f691833ef588b3e to your computer and use it in GitHub Desktop.
Use a batch file request to get file handle URLs for download.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Example code for using Synapse pre-signed URLs to download directly. | |
This only uses the Synapse Python client to perform the POST operation to get | |
the pre-signed URLs and generate signed headers. The `requests` library is used | |
to fetch the file. | |
""" | |
import synapseclient | |
import json | |
import requests | |
import time | |
# Create client | |
syn = synapseclient.login(silent=True) | |
# Get entity | |
e = syn.get('syn20815185', downloadFile=False) | |
# Batch file request object | |
bfr = dict(requestedFiles=[{'associateObjectId': e['id'], | |
'fileHandleId': e['dataFileHandleId'], | |
'associateObjectType': 'FileEntity'}], | |
includePreSignedURLs=True) | |
res = syn.restPOST("/fileHandle/batch", json.dumps(bfr), endpoint=syn.fileHandleEndpoint) | |
headers = syn._generateSignedHeaders(res['requestedFiles'][0]['preSignedURL']) | |
request = requests.get(res['requestedFiles'][0]['preSignedURL'], headers=headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment