Skip to main content

Logging middleware for Bobtail

Project description

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",
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bobtail-upload-0.0.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

bobtail_upload-0.0.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file bobtail-upload-0.0.1.tar.gz.

File metadata

  • Download URL: bobtail-upload-0.0.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for bobtail-upload-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ba9d011e797f48b60862b9c301f318f897b0462fb39bb7b4b535726cd4344c62
MD5 d0025fb2d4c42791c644e1ba69c855c0
BLAKE2b-256 f9edc962d1b0e881bb5457f2216e52ac8d41757e434dc9cdc39b105337b75133

See more details on using hashes here.

File details

Details for the file bobtail_upload-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bobtail_upload-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d2c7b27af83286e4fb0e9b5948486acb1d093aa655c4f4e7f6e39b0bb6cb744f
MD5 aaaed4340cd75e26178269102f04e6a0
BLAKE2b-256 6877924196abb6e03842eb99680d99513a1b8913c555e0b7cb607169046c1f36

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page