File reference
The File
class is a "virtual file" with many of the same methods as the
built-in Python file object. It inherits from Python's
io.RawIOBase
class, which means there are familiar methods like read()
, write()
and close()
. However, because the File class is backed by Edge's storage
system, there are some differences:
- Edge
File
objects are not writeable. This is a limitation of the underlying object store. - Reading from a
File
always returnsbytes
. - They are seekable, but there is high latency associated with this operation as a new HTTP request needs to be sent. For best efficiency, you should do contiguous reads.
- We provide a couple of additional properties and methods:
basename
,size
, anddownload_url
You can use File objects as a context manager, ensuring they are automatically closed:
mysession = EdgeSession()
with mysession.files.open('myfile') as f:
data = f.read()
Constructor
Constructing these yourself is not recommended. They should be retrieved
using the "open" method on Folder objects, for example the
root .files
Folder object on EdgeSession.
Properties
basename
Property (str). The name (not full path) of the file on Edge.
size
Property (int). Size of the file, in bytes.
Methods
download_url
download_url() -> str
Get a signed HTTPS url which can be used to fetch the file. Useful when it's necessary to download a file outside of the Edge API. For example, you can generate a link and pass it to a user's browser, so they can download the file directly to their computer.
read
See io.RawIOBase.read.
readlines
See io.IOBase.readlines.
close
See io.IOBase.close
seek
See io.IOBase.seek.
tell
See io.IOBase.tell.
readable
See io.IOBase.readable.
seekable
See io.IOBase.seekable.
writeable
See io.IOBase.writeable.