Skip to main content

FastAPI Storage Helper

Project description

FastAPI Storage

Introduction

FastAPI Storage provides helper functions for interacting with AWS S3, making it easier to handle file storage, presigned URLs, metadata, and content-type modifications

How to use

Configuration

First, configure the storage service by setting up AWS credentials and bucket information:

# config/storage.py
from fastapi_storage_helper import StorageService
from config.setting import env

storage_service = StorageService(
  access_key_id=env.AWS_ACCESS_KEY_ID,
  secret_key=env.AWS_SECRET_KEY,
  region_name=env.AWS_REGION,
  bucket=env.AWS_S3_BUCKET_NAME,
)

Create Read Presign URL

To generate a presigned URL for reading a file from S3:

from config.storage import storage_service

def get_media_url(self, s3_image_path: str):
    return storage_service.create_read_presign_url(s3_image_path)

Create an Upload Presign URL

To generate a presigned URL for uploading a file to S3:

from config.storage import storage_service
def get_upload_media_url(self, s3_image_path: str):
    return storage_service.create_upload_presign_url(s3_image_path)

Upload file to S3

To directly upload a file to an S3 bucket:

from config.storage import storage_service

def upload_file(self, file: bytes, s3_image_path: str):
    return storage_service.upload_file(file, s3_image_path)

Get metadata

To get metadata for a file stored in S3:

from config.storage import storage_service

def get_metadata(self, s3_image_path: str):
    return storage_service.get_metadata(s3_image_path)

Change Content Type

To modify the content type of a file in S3:

from config.storage import storage_service
def change_content_type(self, s3_image_path: str, content_type: str):
    return storage_service.change_content_type(s3_image_path, content_type)

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

fastapi_storage_helper-0.0.10.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

fastapi_storage_helper-0.0.10-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_storage_helper-0.0.10.tar.gz.

File metadata

File hashes

Hashes for fastapi_storage_helper-0.0.10.tar.gz
Algorithm Hash digest
SHA256 655b239f8d64bba4965f31f3fa706ed80a9d2b443813722c282f337db3f820b2
MD5 2ee1a34a64ed42d1f964925dd2231dc4
BLAKE2b-256 d8eab05b914d448986bc14c33629c3eb0aa1dbdb770b7e2455fb597c971bfa5d

See more details on using hashes here.

File details

Details for the file fastapi_storage_helper-0.0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_storage_helper-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 eee82b27ff1c0705ce4fbb0a9cba11e70f407677417c959a9ffddc33038effeb
MD5 853f7e67d227f37aabb8bbfe10c577f4
BLAKE2b-256 6fad22f133e1e365d6a06f00ebc302cb09628855a4a90c6f87878cfb4c000510

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