:tocdepth: 3 :py:mod:`gws.plugin.upload_helper` ================================== .. py:module:: gws.plugin.upload_helper .. autoapi-nested-parse:: 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:** :source:`gws.plugin.upload_helper` Package Contents ---------------- .. py:class:: ChunkRequest(*args, **kwargs) Bases: :py:obj:`gws.Request` Command request. .. py:attribute:: chunkCount :type: int .. py:attribute:: chunkNumber :type: int .. py:attribute:: content :type: bytes .. py:attribute:: fileName :type: str .. py:attribute:: totalSize :type: int .. py:attribute:: uploadUid :type: str :value: '' .. py:class:: ChunkResponse(*args, **kwargs) Bases: :py:obj:`gws.Response` Command response. .. py:attribute:: uploadUid :type: str .. py:exception:: Error Bases: :py:obj:`gws.Error` Generic GWS error. .. py:class:: Object Bases: :py:obj:`gws.Node` GWS object tree node. .. py:method:: get_upload(uid: str) -> Upload .. py:method:: handle_chunk_request(req: gws.WebRequester, p: ChunkRequest) -> ChunkResponse .. py:class:: Upload(*args, **kwargs) Bases: :py:obj:`gws.Data` Basic data object. This object can be instantiated by passing one or or ``dict`` arguments and/or keyword args. All dicts keys and keywords become attributes of the object. Accessing an undefined attribute returns ``None`` and no error is raised, unless the attribute name starts with an underscore. .. py:attribute:: fileName :type: str .. py:attribute:: path :type: str .. py:attribute:: totalSize :type: int .. py:attribute:: uploadUid :type: str