Setup Proxy Local - Sage-Bionetworks/file-proxy GitHub Wiki
Setup Proxy-Local
This is an example of setting up the file-proxy to serve files from a locally mounted drive.
Configuration
The following Java properties must be provided to the file-proxy server (-Dkey=value):
Property Name | Description |
---|---|
org.sagebionetworks.url.signer.secret.key | The credentials used to sign pre-signed URLs. The credentials should match the value of the 'ProxyStorageLocationSettings.secretKey' set in Synapse. |
org.sagebionetworks.local.path.prefix | Required to server files locally. Callers will request files by providing a relative path. An additional path prefix is needed to resolve these relative paths to actual files. This configuration provides this path prefix. |
Proxy Server
In this example proxy server will be launched locally. The proxy server must be configured with the secret key used to sign URLs generated from Synapse and the path prefix.
git clone https://github.com/Sage-Bionetworks/file-proxy.git
cd file-proxy
The proxy server can then be started by passing all of the relevant configuration information as system properties (-Dkey=value) as follows
mvn tomcat:run -D"org.sagebionetworks.url.signer.secret.key=<url_signer_key>" -D"org.sagebionetworks.local.path.prefix=C:/Users/John/Downloads"
console output:
[INFO] --- tomcat-maven-plugin:1.1:run (default-cli) @ file-proxy ---
[INFO] Running war on http://localhost:8080/file-proxy
[INFO] Using existing Tomcat server configuration at C:\cygwin64\home\jhill\git\file-proxy\target\tomcat
Feb 08, 2016 4:16:18 PM org.apache.catalina.startup.Embedded start
INFO: Starting tomcat server
Feb 08, 2016 4:16:19 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
Feb 08, 2016 4:16:19 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 08, 2016 4:16:19 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
The console shows the proxy server running at URL as http://localhost:8080/file-proxy
ProxyStorageLocationSettings
Before we can start creating ProxyFileHandles for the above setups we must first register a new StorageLocation with Synapse. The ProxyStorageLocationSettings contains all of the parameters Synapse will need to generated ProxyFileHandles and to issue pre-signed URL for ProxyFileHandles. The following curl call was used to create the ProxyStorageLocationSettings:
curl -k -H "sessionToken:<session_token>" -H "Content-Type: application/json" -X POST -d '{"uploadType":"PROXYLOCAL","secretKey":"<url_signer_key>", "proxyUrl":"https://localhost:8080/file-proxy", "concreteType":"org.sagebionetworks.repo.model.project.ProxyStorageLocationSettings"}' https://repo-prod.prod.sagebase.org/repo/v1/storageLocation
response:
{"createdOn":"2016-02-09T00:42:06.942Z","uploadType":"PROXYLOCAL","concreteType":"org.sagebionetworks.repo.model.project.ProxyStorageLocationSettings","secretKey":"<url_signer_key>","etag":"251fbeeb-3004-47dc-86af-56a11d2a8b3f","createdBy":273991,"proxyUrl":"https://localhost:8080/file-proxy","storageLocationId":4171}
ProxyFileHandle
Once the proxy servers started and the ProxyStorageLocationSettings is created in Synapse, we can start creating ProxyFileHandles for each file.
curl -k -H "sessionToken:<session_token>" -H "Content-Type: application/json" -X POST -d '{"storageLocationId":"4171", "filePath":"/public/downloads/Before.png", "fileName":"Before.png", "contentType":"image/png", "contentMd5":"md5", "contentSize":"29486", "concreteType":"org.sagebionetworks.repo.model.file.ProxyFileHandle"}' https://repo-prod.prod.sagebase.org/file/v1/externalFileHandle/proxy
Response:
{"id":"7512152","createdOn":"2016-02-09T00:46:32.000Z","concreteType":"org.sagebionetworks.repo.model.file.ProxyFileHandle","etag":"8421db63-5167-438c-a7df-15534d9290de","createdBy":"273991","contentSize":29486,"filePath":"/public/downloads/Before.png","fileName":"Before.png","contentType":"image/png","contentMd5":"md5","storageLocationId":4170}
File download
The final step is to test downloading the file through the proxy by fetching a pre-signed URL for the ProxyFileHandle from Synapse:
curl -k -H "sessionToken:<session_token>" "https://repo-prod.prod.sagebase.org/file/v1/fileHandle/7512152/url?redirect=false"
Response:
https://localhost:8080/file-proxy/sftp/public/downloads/Before.png?fileName=Before.png&contentType=image%2Fpng&contentMD5=md5&contentSize=29486&expiration=1454979041142&hmacSignature=f1289a824901a6fc1af3286cb404fb94adb667b6