Hello,
We have files on Synapse that we'd like to access via streaming. Could you advise how to go about that? I've looked a bit at the Python API but don't see anything obvious.
Best
Neva Durand
Created by Neva Durand neva Thank you! That worked. Oops! I've edited the previous reply. The final line should have wrapped the `batch_file_request` in `json.dumps` to convert the Python dictionary to JSON:
```python
result = syn.restPOST(uri='/fileHandle/batch', body=json.dumps(batch_file_request), endpoint=syn.fileHandleEndpoint)
```
Thanks so much for the help.
I've tried the Python code and I'm getting this error at the line "result = ...":
synapseclient.exceptions.SynapseHTTPError: 400 Client Error:
A JSONObject text must begin with '{' at character 1; nested exception is org.sagebionetworks.schema.adapter.JSONObjectAdapterException: org.json.JSONException: A JSONObject text must begin with '{' at character 1
Is there something wrong with the batch_file_request? Thanks @jay !
You can do this in Python as well with a convenience function:
```python
import json
import synapseclient
syn = synapseclient.login()
batch_file_request = {
"requestedFiles": [
{
"fileHandleId": "14062807",
"associateObjectId": "syn7809125",
"associateObjectType": "FileEntity"
},
{
"fileHandleId": "16913067",
"associateObjectId": "422375",
"associateObjectType": "WikiAttachment"
}
],
"includePreSignedURLs": True,
"includeFileHandles": False
}
result = syn.restPOST(uri='/fileHandle/batch', body=json.dumps(batch_file_request), endpoint=syn.fileHandleEndpoint)
``` Hello @neva ,
I recommend you try using the [POST /fileHandle/batch](https://docs.synapse.org/rest/POST/fileHandle/batch.html) REST call. You define the file set via a [BatchFileRequest](https://docs.synapse.org/rest/org/sagebionetworks/repo/model/file/BatchFileRequest.html) , and this service will respond with a [BatchFileResult](https://docs.synapse.org/rest/org/sagebionetworks/repo/model/file/BatchFileResult.html) that contains the presigned URLs.
For example, this is the cURL command to request a presigned URL to a Synapse File, and a presigned URL to a file attached to a Wiki:
```
curl -i -k -H sessionToken:xxxxxxxxxxxx -H Accept:application/json -H Content-Type:application/json -d '{
"requestedFiles": [
{
"fileHandleId": "14062807",
"associateObjectId": "syn7809125",
"associateObjectType": "FileEntity"
},
{
"fileHandleId": "16913067",
"associateObjectId": "422375",
"associateObjectType": "WikiAttachment"
}
],
"includePreSignedURLs": true,
"includeFileHandles": false
}' https://repo-prod.prod.sagebase.org/file/v1/fileHandle/batch
```
More information about [this service](https://docs.synapse.org/rest/POST/fileHandle/batch.html) (and other available service calls) can be found in the [Synapse REST API docs](https://docs.synapse.org/rest/index.html). Thanks. Could you expand further on how one would use the REST APIs in this manner? Unfortunately, this isn't possible in the Python/R clients. In theory one could use the REST APIs to get a URL that can be read from directly. This would also mean that robustness retries etc would have to be handled by the consumer of the stream.