Skip to content

Use a document loader on a non-local, uploaded document (via FastAPI/starlette.datastructures.UploadFile)? #17982

Answered by pastram-i
pastram-i asked this question in Q&A
Discussion options

You must be logged in to vote

@matisidler - I've settled on a bit of a workaround instead of a solution. I upload to s3 using boto3, then use the S3FileLoader. I've just settled on this solution within the last week, so I haven't tested in thoroughly, but afaik it should be file type agnostic.

from fastapi import FastAPI
from fastapi import UploadFile, File

from langchain_community.document_loaders import S3FileLoader

from datetime import datetime
from uuid import uuid5, NAMESPACE_DNS

app = FastAPI()

s3_bucket = "xyz"


@app.post("/")
async def example(
    file: UploadFile = File(None),
):
    session = boto3.Session()
    s3_client = session.client("s3", config=Config(signature_version='s3v4'))
    file_id = uuid5(

Replies: 3 comments 8 replies

Comment options

You must be logged in to vote
5 replies
@pastram-i
Comment options

@dosubot
Comment options

@pastram-i
Comment options

@dosubot
Comment options

@dosubot
Comment options

Comment options

You must be logged in to vote
3 replies
@pastram-i
Comment options

Answer selected by pastram-i
@rarchitgupta
Comment options

@rarchitgupta
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants