Fastapi: [QUESTION]

Created on 22 Mar 2020  路  3Comments  路  Source: tiangolo/fastapi

First check

  • [ x] I used the GitHub search to find a similar issue and didn't find it.
  • [x ] I searched the FastAPI documentation, with the integrated search.
  • [ x] I already searched in Google "How to X in FastAPI" and didn't find any information.

Description

Using file:

file: UploadFile = File(...)

I try to put the file-like object into an s3 bucket:

s3_response = s3.Bucket(bucket_name).put_object(Key=file.filename, Body=file)

i get the error:


start_position = fileobj.tell()
AttributeError: 'UploadFile' object has no attribute 'tell'

I'm assuming i need to either implement tell(), or convert to a bytes

Would there be other options?

And if so, how you recommend into converting UploadFile into a bytes efficiently?

question

Most helpful comment

UploadedFile has a member file which might help. So instead of using s3_response = s3.Bucket(bucket_name).put_object(Key=file.filename, Body=file) it might help using s3_response = s3.Bucket(bucket_name).put_object(Key=file.filename, Body=file.file)

All 3 comments

UploadedFile has a member file which might help. So instead of using s3_response = s3.Bucket(bucket_name).put_object(Key=file.filename, Body=file) it might help using s3_response = s3.Bucket(bucket_name).put_object(Key=file.filename, Body=file.file)

that worked, thank you

Thanks for the help here @merowinger92 ! :bowing_man: :cake:

Thanks for reporting back and closing the issue @joeraygme :+1:

Was this page helpful?
0 / 5 - 0 ratings