kotti.filedepot¶
-
class
kotti.filedepot.
DBFileStorage
[source]¶ Implementation of
depot.io.interfaces.FileStorage
,Uses kotti.filedepot.DBStoredFile to store blob data in an SQL database.
-
create
(content, filename=None, content_type=None)[source]¶ Saves a new file and returns the file id
Parameters: - content – can either be
bytes
, anotherfile object
or acgi.FieldStorage
. Whenfilename
andcontent_type
parameters are not provided they are deducted from the content itself. - filename (string) – filename for this file
- content_type (string) – Mimetype of this file
Returns: the unique
file_id
associated to this fileReturn type: string
- content – can either be
-
delete
(file_or_id)[source]¶ Deletes a file. If the file didn’t exist it will just do nothing.
Parameters: file_or_id – can be either DBStoredFile
or afile_id
-
exists
(file_or_id)[source]¶ Returns if a file or its ID still exist.
Returns: Returns if a file or its ID still exist. Return type: bool
-
get
(file_id)[source]¶ Returns the file given by the file_id
Parameters: file_id (string) – the unique id associated to the file Result: a kotti.filedepot.DBStoredFile
instanceReturn type: kotti.filedepot.DBStoredFile
-
list
(*args)[source]¶ Returns a list of file IDs that exist in the Storage.
Depending on the implementation there is the possibility that this returns more IDs than there have been created. Therefore this method is NOT guaranteed to be RELIABLE.
-
replace
(file_or_id, content, filename=None, content_type=None)[source]¶ Replaces an existing file, an
IOError
is raised if the file didn’t already exist.Given a
StoredFile
or its ID it will replace the current content with the providedcontent
value. Iffilename
andcontent_type
are provided or can be deducted by thecontent
itself they will also replace the previous values, otherwise the current values are kept.Parameters: - file_or_id – can be either
DBStoredFile
or afile_id
- content – can either be
bytes
, anotherfile object
or acgi.FieldStorage
. Whenfilename
andcontent_type
parameters are not provided they are deducted from the content itself. - filename (string) – filename for this file
- content_type (string) – Mimetype of this file
- file_or_id – can be either
-
-
class
kotti.filedepot.
DBStoredFile
(file_id, filename=None, content_type=None, last_modified=None, content_length=None, **kwds)[source]¶ depot.io.interfaces.StoredFile
implementation that stores file data in SQL database.Can be used together with
kotti.filedepot.DBFileStorage
to implement blobs storage in the database.-
close
(*args, **kwargs)[source]¶ Implement
StoredFile.close()
.DBStoredFile
never closes.
-
content_length
¶ Size of the blob in bytes (
sqlalchemy.types.Integer
)
-
content_type
¶ MIME type of the blob (
sqlalchemy.types.String
)
-
data
¶ The binary data itself (
sqlalchemy.types.LargeBinary
)
-
file_id
¶ Unique file id given to this blob (
sqlalchemy.types.String
)
-
filename
¶ The original filename it had when it was uploaded. (
sqlalchemy.types.String
)
-
id
¶ Primary key column in the DB (
sqlalchemy.types.Integer
)
-
last_modified
¶ Date / time the blob was created or last modified (
sqlalchemy.types.DateTime
)
-
name
¶ Implement
StoredFile.name()
.Result: the filename of the saved file Return type: string
-
public_url
¶ Integration with
depot.middleware.DepotMiddleware
When supported by the storage this will provide the public url to which the file content can be accessed. In case this returns
None
it means that the file can only be served by thedepot.middleware.DepotMiddleware
itself.
-
read
(n=-1)[source]¶ Reads
n
bytes from the file.If
n
is not specified or is-1
the whole file content is read in memory and returned
-