core.modules.file

Module Contents

Classes

InjectStoreURLBone

fileBaseSkel

Default file leaf skeleton.

fileNodeSkel

Default file node skeleton.

File

Functions

importBlobFromViur2(dlKey, fileName)

thumbnailer(fileSkel, existingFiles, params)

decodeFileName(name)

startCheckForUnreferencedBlobs()

Start searching for blob locks that have been recently freed

doCheckForUnreferencedBlobs([cursor])

startCleanupDeletedFiles()

Increase deletion counter on each blob currently not referenced and delete

doCleanupDeletedFiles([cursor])

Attributes

client

bucket

iamClient

json

html

core.modules.file.client
core.modules.file.bucket
core.modules.file.iamClient
core.modules.file.importBlobFromViur2(dlKey, fileName)
class core.modules.file.InjectStoreURLBone

Bases: viur.core.bones.BaseBone

unserialize(skel, name)
core.modules.file.thumbnailer(fileSkel, existingFiles, params)
class core.modules.file.fileBaseSkel

Bases: viur.core.prototypes.tree.TreeSkel

Default file leaf skeleton.

kindName = file
size
dlkey
name
mimetype
weak
pending
width
height
downloadUrl
derived
pendingparententry
preProcessBlobLocks(locks)

Ensure that our dlkey is locked even if we don’t have a filebone here

classmethod refresh(skelValues)
class core.modules.file.fileNodeSkel

Bases: viur.core.prototypes.tree.TreeSkel

Default file node skeleton.

kindName = file_rootNode
name
rootNode
core.modules.file.decodeFileName(name)
class core.modules.file.File

Bases: viur.core.prototypes.tree.Tree

leafSkelCls
nodeSkelCls
maxuploadsize
uploadHandler = []
adminInfo
blobCacheTime
write(filename: str, content: Any, mimetype: str = 'text/plain', width: int = None, height: int = None) viur.core.db.Key

Write a file from any buffer into the file module.

Parameters
  • filename – Filename to be written.

  • content – The file content to be written, as bytes-like object.

  • mimetype – The file’s mimetype.

  • width – Optional width information for the file.

  • height – Optional height information for the file.

Returns

Returns the key of the file object written. This can be associated e.g. with a FileBone.

deleteRecursive(parentKey)
signUploadURL(mimeTypes: Union[List[str], None] = None, maxSize: Union[int, None] = None, node: Union[str, None] = None)

Internal helper that will create a signed upload-url that can be used to retrieve an uploadURL from getUploadURL for guests / users without having file/add permissions. This URL is valid for an hour and can be used to upload multiple files. :param mimeTypes: A list of valid mimetypes that can be uploaded (wildcards like “image/*” are supported) or

None (no restriction on filetypes)

Parameters
  • maxSize – The maximum filesize in bytes or None for no limit

  • node

    The (string encoded) key of a file-leaf (=directory) where this file will be uploaded into or None (the file will then not show up in the filebrowser). .. Warning:

    If node is set it's the callers responsibility to ensure node is a valid key and that the user has
    the permission to upload into that directory. ViUR does *not* enforce any canAccess restrictions for
    keys passed to this function!
    

Returns

authData and authSig for the getUploadURL function below

initializeUpload(fileName: str, mimeType: str, node: Union[str, None], size: Union[int, None] = None) Tuple[str, str]

Internal helper that registers a new upload. Will create the pending fileSkel entry (needed to remove any started uploads from GCS if that file isn’t used) and creates a resumable (and signed) uploadURL for that. :param fileName: Name of the file that will be uploaded :param mimeType: Mimetype of said file :param node: If set (to a string-key representation of a file-node) the upload will be written to this directory :param size: The exact filesize we’re accepting in Bytes. Used to enforce a filesize limit by getUploadURL :return: Str-Key of the new file-leaf entry, the signed upload-url

getUploadURL(fileName, mimeType, size=None, skey=None, *args, **kwargs)
download(blobKey: str, fileName: str = '', download: str = '', sig: str = '', *args, **kwargs)

Download a file. :param blobKey: The unique blob key of the file. :param fileName: Optional filename to provide in the header. :param download: Set header to attachment retrival, set explictly to “1” if download is wanted.

add(skelType: viur.core.prototypes.tree.SkelType, node=None, *args, **kwargs)
onItemUploaded(skel)
core.modules.file.json = True
core.modules.file.html = True
core.modules.file.startCheckForUnreferencedBlobs()

Start searching for blob locks that have been recently freed

core.modules.file.doCheckForUnreferencedBlobs(cursor=None)
core.modules.file.startCleanupDeletedFiles()

Increase deletion counter on each blob currently not referenced and delete it if that counter reaches maxIterCount

core.modules.file.doCleanupDeletedFiles(cursor=None)