CoCalc
Sharedsupport / 2015-10-25-103848-file-raw.sagewsOpen in CoCalc

Examples for support purposes...

smc.file?

File: /projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/.sagemathcloud/sage_server.py
Docstring :
Display or provide a link to the given file.  Raises a RuntimeError
if this is not possible, e.g, if the file is too large.

If show=True (the default), the browser will show the file, or
provide a clickable link to it if there is no way to show it.

If show=False, this function returns an object T such that T.url
(or str(t)) is a string of the form "/blobs/filename?uuid=the_uuid"
that can be used to access the file even if the file is immediately
deleted after calling this function (the file is stored in a
database). Also, T.ttl is the time to live (in seconds) of the
object.  A ttl of 0 means the object is permanently available.

raw=False (the default):
If you use the URL

then the server will include a header that tells the browser to
relatively small files can be made available this way.  However,
they remain available (for a day) even *after* the file is
deleted. NOTE: It is safe to delete the file immediately after
this function (salvus.file) returns.

raw=True:
Instead, the URL is to the raw file, which is served directly
from the project:

/project-id/raw/path/to/filename

This will only work if the file is not deleted; however,
arbitrarily large files can be streamed this way.

This function creates an output message {file:...}; if the user
saves a worksheet containing this message, then any referenced
blobs are made permanent in the database.

The uuid is based on the Sha-1 hash of the file content (it is
computed using the function sage_server.uuidsha1).  Any two files
with the same content have the same Sha1 hash.