Giter VIP home page Giter VIP logo

fastfiles's Introduction

fastfiles

File storage (Local, Memory, and Cloud) for fastapi. Proof of concept for filestore

from fastapi import FastAPI, Request, Depends
from fastapi.templating import Jinja2Templates
from dotenv import load_dotenv

from fastfiles import S3, Local, Memory, FileData

load_dotenv()

app = FastAPI()
templates = Jinja2Templates(directory='')

s3 = S3(extra_args={'ACL': 'public-read'})
memory = Memory()
local = Local()

@app.get('/')
async def home(req: Request):
    return templates.TemplateResponse('home.html', {'request': req})

# Upload to s3. For single file upload we assume the file input element name is file
@app.post('/s3_upload', name='s3_upload')
async def upload(file: FileData = Depends(s3)) -> FileData:
    return file

# Upload to local disk. For multiple file upload we assume the file input element name is files.
@app.post('/local_upload', name='local_upload')
async def upload(files: list[FileData] = Depends(local)) -> list[FileData]:
    return files

# Upload to memory.
@app.post('/memory_upload', name='memory_upload')
async def upload(file: FileData = Depends(memory)) -> FileData:
    return file

S3 Usage

To use s3 make sure the following environment variables are set

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_DEFAULT_REGION
  • AWS_BUCKET_NAME

fastfiles's People

Contributors

ichinga-samuel avatar

Stargazers

SHUBHAM SHANKAR avatar Likhit avatar  avatar Emmanuel Evbuomwan avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.