fastapi-gcs
Fast API GCS
Requirements
Python 3.7+
Installation
$ pip install fast-api-gcs
---> 100%
Example
Create it
- Create a file
main.py
with:
from fastapi_gcs import FGCSUpload, FGCSGenerate, FGCSDelete
from fastapi import FastAPI, File, UploadFile
app = FastAPI()
@app.post("/upload-file/")
async def create_upload_file(file: UploadFile):
return await FGCSUpload.file(
project_id={google_project_id},
bucket_name={google_bucket_name},
file=file,
file_path='my_data/test',
maximum_size=2_097_152,
allowed_extension= ['png', 'jpg'],
)
@app.post("/upload-ecrypted-file/")
async def create_upload_file(file: UploadFile):
return await FGCSUpload.encrypted_file(
project_id={google_project_id},
bucket_name={google_bucket_name},
file=file,
file_path='my_data/test',
maximum_size=2_097_152,
allowed_extension= ['png', 'jpg'],
)
@app.post("/generate-signed-url/")
async def create_upload_file(file_path: str):
return await FGCSGenerate.signed_url(
project_id={google_project_id},
bucket_name={google_bucket_name},
file_path=file_path
expiration_hour=1
)
@app.post("/delete_file/")
async def create_upload_file(file_path: str):
await FGCSDelete.file(
project_id={google_project_id},
bucket_name={google_bucket_name},
file_path=file_path
)