upload.views - Views for Uploading and Downloading Files
- upload.views.UPLOAD_HANDLE_HEADER = 'X-Upload-Handle'
HTTP header used to convey the opaque per-wizard upload handle for the session-token-less upload endpoints.
- class upload.views.FileUploadResponse(accepted: bool, error: str | None = None, verbose_error: str | None = None, file: str | None = None, url: str | None = None, status: int = 200, **kwargs)
Bases:
JsonResponseStructured JSON response to send to a client when a file is uploaded.
- upload.views.upload_or_list_files(request: HttpRequest) JsonResponse
Upload a single file to the server list the files uploaded in a given upload session.
The proper upload session is retrieved by way of accessing the request’s session data. This must contain a valid upload handle to list or upload files. This ID is set by the form wizard.
When uploading, the file type is checked against this application’s ACCEPTED_FILE_FORMATS setting, if the file is not an accepted type, an error message is returned.
- Parameters:
request – The HTTP GET or POST request
session_token – The upload session token from the URL
- Returns:
If the response is not successful, the error message
erroris included in the response. When getting files, thefileskey is returned. When uploading files, thefileandurlkeys are returned when successful, along withaccepted, which indicates whether the file was accepted.- Return type:
JsonResponse
- upload.views.uploaded_file_by_uuid(request: HttpRequest, file_uuid: UUID) HttpResponse
Serve an uploaded file looked up by its opaque per-file UUID.
- Parameters:
request – The HTTP request.
file_uuid – The per-file UUID generated when the file was uploaded.
- Returns:
Redirects to the file’s media path in development, or returns an X-Accel-Redirect in production. 404 if the file does not exist or is not accessible to the requester.
- Return type:
HttpResponse
- upload.views.uploaded_file_by_name(request: HttpRequest, file_name: str) HttpResponse
Get or delete a previously-uploaded file identified by the name and the upload handle.
The upload session is resolved from the X-Upload-Handle header.
- Parameters:
request – The HTTP DELETE or GET request. The header
X-Upload-Handlemust contain a valid handle previously registered by the form wizard.file_name – The name of the file to retrieve or delete
- Returns:
204 on successful DELETE; for GET, redirects to the file’s media path in development, or returns an X-Accel-Redirect to the file’s media path in production. 404 if the file or session cannot be resolved.
- Return type:
HttpResponse