py4cytoscape.sandbox.sandbox_url_to¶
-
sandbox_url_to
(source_url, dest_file, overwrite=True, sandbox_name=None, base_url='http://127.0.0.1:1234/v1')[source]¶ Transfer a cloud-based file to a sandbox.
The source URL identifies a file to be transferred to the named (or current) sandbox, overwriting an existing file if one already exists. The
dest_file
can be an absolute path if the sandbox is the entire file system (i.e., for standalone Python execution), or it can be a path relative to the sandbox (i.e., for Notebook or remote execution or if a sandbox was explicitly created).- Supported URLs include:
Raw URL: URL directly references the file to download (e.g., http://tpsoft.com/museum_images/IBM%20PC.JPG
Dropbox: Use the standard Dropbox
Get Link
feature to create thesource_url
link in the clipboard (e.g., https://www.dropbox.com/s/r15azh0xb53smu1/GDS112_full.soft?dl=0)GDrive: Use the standard Google Drive
Get Link
feature to create thesource_url
link in the clipboard (e.g., https://drive.google.com/file/d/12sJaKQQbesF10xsrbgiNtUcqCQYY1YI3/view?usp=sharing)OneDrive: Use the OneDrive web site to right click on the file, choose the
Embed
menu option, then copy the URL in the iframe’ssrc
parameter into the clipboard (e.g., https://onedrive.live.com/embed?cid=C357475E90DD89C4&resid=C357475E90DD89C4%217207&authkey=ACEU5LrVtI_jWTU)GitHub: Use the GitHub web site to show the file or a link to it, and capture the URL in the clipboard (e.g., https://github.com/cytoscape/file-transfer-app/blob/master/test_data/GDS112_full.soft)
Note that GitHub enforces a limit on the size of a file that can be stored there. We advise that you take this into account when choosing a cloud service for your files.
When you capture a URL in the clipboard, you should copy it into your program for use with
sandbox_url_to()
.
This function is most useful for Notebooks executing on a remote server. For Notebooks running on the local Cytoscape workstation, consider using the import_file_from_url() function if the Notebook is not intended to ever run on a remote server.
- Parameters
source_url (str) – URL addressing cloud file to download
dest_file (str) – Name of file to write (as absolute path or sandbox-relative path)
overwrite (bool) – False causes error if dest_file already exists; True replaces it if it exists
sandbox_name (str) – Name of sandbox containing file. None means “the current sandbox”.
base_url (str) – Ignore unless you need to specify a custom domain, port or version to connect to the CyREST API. Default is http://localhost:1234 and the latest version of the CyREST API supported by this version of py4cytoscape.
- Returns
{‘filePath’: <new file’s absolute path in Cytoscape workstation>, ‘fileByteCount’: number of bytes read}
- Return type
dict
- Raises
CyError – if file name or URL is invalid
requests.exceptions.HTTPError – if can’t connect to Cytoscape, Cytoscape returns an error, or sandbox is invalid
Examples
>>> sandbox_url_to('https://www.dropbox.com/s/r15azh0xb53smu1/GDS112_full.soft?dl=0', 'test file') {'filePath': 'C:\Users\CyDeveloper\CytoscapeConfiguration\filetransfer\default_sandbox\test file', 'fileByteCount': 5536880} >>> sandbox_url_to('https://www.dropbox.com/s/r15azh0xb53smu1/GDS112_full.soft?dl=0', 'test file', overwrite=True) {'filePath': 'C:\Users\CyDeveloper\CytoscapeConfiguration\filetransfer\default_sandbox\test file', 'fileByteCount': 5536880} >>> sandbox_url_to('https://www.dropbox.com/s/r15azh0xb53smu1/GDS112_full.soft?dl=0', 'test file', sandbox_name='mySand') {'filePath': 'C:\Users\CyDeveloper\CytoscapeConfiguration\filetransfer\mysand\test file', 'fileByteCount': 5536880}
See also
Sandboxing in the Concepts section in the py4cytoscape User Manual.