home / docs / sections

sections: internals:internals-uploadedfile

This data as json

id page ref title content breadcrumbs references
internals:internals-uploadedfile internals internals-uploadedfile The UploadedFile class When parsing multipart form data with files=True , file uploads are returned as UploadedFile objects with the following properties and methods: uploaded_file.name - string The form field name. uploaded_file.filename - string The original filename provided by the client. Note: This is sanitized to remove path components for security. uploaded_file.content_type - string or None The MIME type of the uploaded file, if provided by the client. uploaded_file.size - integer The size of the uploaded file in bytes. await uploaded_file.read(size=-1) - bytes Read and return up to size bytes from the file. If size is -1 (default), read the entire file. await uploaded_file.seek(offset, whence=0) - integer Seek to the given position in the file. Returns the new position. await uploaded_file.close() Close the underlying file. This is called automatically when the object is garbage collected. Files smaller than 1MB are stored in memory. Larger files are automatically spilled to temporary files on disk and cleaned up when the request completes. Example: form = await request.form(files=True) uploaded = form["document"] # Check file metadata print(f"Filename: {uploaded.filename}") print(f"Content-Type: {uploaded.content_type}") print(f"Size: {uploaded.size} bytes") # Read file content content = await uploaded.read() # Or read in chunks await uploaded.seek(0) while chunk := await uploaded.read(8192): process_chunk(chunk) ["Internals for plugins"] []
Powered by Datasette · Queries took 3.81ms