upload.views - Views for Uploading and Downloading Files
- upload.views.upload_or_list_files(request: HttpRequest, session_token: str) JsonResponse
Upload a single file to the server list the files uploaded in a given upload session. The file is added to the upload session using the session token passed as a parameter in the request. If a session token is invalid, an error message is returned.
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 list or upload operation was successful, the session token uploadSessionToken is included in the response. If not successful, the error description error is included.
- Return type:
JsonResponse
- upload.views.readonly_uploaded_file(request: HttpRequest, session_token: str, file_name: str) HttpResponse
Get a file that has been uploaded in a given upload session.
This view is suitable for viewing files when file uploads are disabled. Otherwise, not having a DELETE request will make it so that users can’t remove files from the upload files part of the form. Use
uploaded_filefor that instead.- Parameters:
request – The HTTP request
session_token – The upload session token from the URL
file_name – The name of the file to delete
- Returns:
Redirects to the file’s media path in development, or returns an X-Accel-Redirect to the file’s media path if in production.
- Return type:
HttpResponse
- upload.views.uploaded_file(request: HttpRequest, session_token: str, file_name: str) HttpResponse
Get or delete a file that has been uploaded in a given upload session.
- Parameters:
request – The HTTP request
session_token – The upload session token from the URL
file_name – The name of the file to delete
- Returns:
In the case of deletion, returns a 204 response when successfully deleted. In the case of getting a file, redirects to the file’s media path in development, or returns an X-Accel-Redirect to the file’s media path if in production.
- Return type:
HttpResponse