Skip to main content

Bobtail File Upload

Middleware to upload files for Bobtail

Install

pip install bobtail-upload

Usage

from bobtail_upload import BobtailUpload

app = Bobtail(routes=routes)

app.use(BobtailUpload(options={}))

Saving files

Bobtail Upload will attach the an Upload API to the request object There are 2 methods now available:

  • add(self, *, file_name: str, data: bytes, mimetype: str) -> None
  • save(self, *, table_name: str = None, pk: Union[int, str] = None) -> None
def post(self, req: Request, res: Response):
    data = req.get_multipart_data()
    req.upload.add(
        file_name=data["logo"]["value"]["filename"],
        data=data["logo"]["value"]["file_data"],
        mimetype=data["logo"]["value"]["mimetype"],
    )
    
    req.upload.save()

Mapping file saves to your database tables

To save files based on a table name & primary key.

The default upload directory path is /uploads

- uploads
  - images
    - 2

For example

def post(self, req: Request, res: Response):
    data = req.get_multipart_data()
    req.upload.add(
        file_name=data["logo"]["value"]["filename"],
        data=data["logo"]["value"]["file_data"],
        mimetype=data["logo"]["value"]["mimetype"],
    )
    
    # Use your ORM to save the file to your db & obtain the returned primary key (pk)
    req.upload.save(table_name="images", pk=pk)

Options

  • UPLOAD_DIR - the directory path where files will be saved (defaults to uploads).
options = {
    "UPLOAD_DIR": "uploads",
}

Metadata

Release files for bobtail-upload 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bobtail-upload 0.0.1
File Size Uploaded
bobtail-upload-0.0.1.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bobtail-upload 0.0.1
File Interpreter ABI Platform
bobtail_upload-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.0 kB

Release files / bobtail-upload-0.0.1.tar.gz

Download URL bobtail-upload-0.0.1.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ba9d011e797f48b60862b9c301f318f897b0462fb39bb7b4b535726cd4344c62
BLAKE2b-256 checksum
How to use checksums
f9edc962d1b0e881bb5457f2216e52ac8d41757e434dc9cdc39b105337b75133
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / bobtail_upload-0.0.1-py3-none-any.whl

Download URL bobtail_upload-0.0.1-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2c7b27af83286e4fb0e9b5948486acb1d093aa655c4f4e7f6e39b0bb6cb744f
BLAKE2b-256 checksum
How to use checksums
6877924196abb6e03842eb99680d99513a1b8913c555e0b7cb607169046c1f36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page