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)¶
Bases:
gws.RequestCommand request.
- chunkCount: int¶
- chunkNumber: int¶
- content: bytes¶
- fileName: str¶
- totalSize: int¶
- uploadUid: str = ''¶
- class gws.plugin.upload_helper.ChunkResponse(*args, **kwargs)¶
Bases:
gws.ResponseCommand response.
- uploadUid: str¶
- class gws.plugin.upload_helper.Object¶
Bases:
gws.NodeGWS object tree node.
- handle_chunk_request(req: gws.WebRequester, p: ChunkRequest) ChunkResponse¶
- class gws.plugin.upload_helper.Upload(*args, **kwargs)¶
Bases:
gws.DataBasic 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.- fileName: str¶
- path: str¶
- totalSize: int¶
- uploadUid: str¶