gws.plugin.upload_helper¶
Manage chunked uploads.
In your action, declare an endpoint with p: ChunkRequest as a parameter. This endpoint should invoke handle_chunk_request:
import gws.plugin.upload_helper as uh
@gws.ext.command.api('myUpload')
def do_upload(self, req, p: uh.ChunkRequest) -> uh.ChunkResponse:
# check permissions, etc...
helper = self.root.app.helper('upload')
return helper.handle_chunk_request(req, p)
...
The client sends chunks to this endpoint, one by one. Each chunk contains the file name and total size. The first chunk has an empty uploadUid, indicating a new upload. Subsequent chunks must provide a valid uploadUid. The handler responds with an uploadUid. Each chunk must have a serial number, starting from 0. Chunks can come in any order.
Once the client decides that the upload is complete, it proceeds with invoking some other endpoint of your action, mentioning the uploadUid returned by the first chunk. The endpoint should invoke get_upload to retrieve the final file. The file is stored in a temporary location and should be moved to a permanent location if necessary:
@gws.ext.command.api('myProcessUploadedFile')
def do_process(self, req, p: MyProcessRequest):
helper = self.root.app.helper('upload')
try:
upload = helper.get_upload(p.uploadUid)
except uh.Error:
...upload not ready yet...
...process(upload.path)
Source code: gws.plugin.upload_helper
Package Contents¶
- class gws.plugin.upload_helper.ChunkRequest(*args, **kwargs)¶
Command request.
- chunkCount: int¶
- chunkNumber: int¶
- content: bytes¶
- fileName: str¶
- totalSize: int¶
- uploadUid: str = ''¶
- class gws.plugin.upload_helper.Config(*args, **kwargs)¶
Upload helper.
- maxSize: int = 1000¶
Maximum upload size in megabytes.
- exception gws.plugin.upload_helper.Error¶
Generic GWS error.
- class gws.plugin.upload_helper.Object¶
GWS object tree node.
- maxChunkCount: int¶
- maxSize: int¶
- configure()¶
Configuration hook.
- handle_chunk_request(req: gws.WebRequester, p: ChunkRequest) ChunkResponse¶
- class gws.plugin.upload_helper.Upload(*args, **kwargs)¶
Basic data object.
This object can be instantiated by passing one or or
dictarguments and/or keyword args. All dicts keys and keywords become attributes of the object.Accessing an undefined attribute returns
Noneand no error is raised, unless the attribute name starts with an underscore.- chunkCount: int¶
- fileName: str¶
- path: str¶
- totalSize: int¶
- uid: str¶