Code Monkey home page Code Monkey logo

Comments (5)

timbusfield avatar timbusfield commented on August 20, 2024 1

@abdelhai you have more faith in the users than I do :) I've seen a few instances of incorrect file extensions the past.
I'd probably use a module like this one to make the conversion, if I was going to take that approach:
https://docs.python.org/3/library/mimetypes.html

The tool I'm working on should accept any file type really so I'll need to test it on quite a few different file types. Thanks for your help.

from deta-python.

timbusfield avatar timbusfield commented on August 20, 2024

This is the png I used for testing:
http://clipart-library.com/image_gallery/320477.png

from deta-python.

abdelhai avatar abdelhai commented on August 20, 2024

@timbusfield
You need to pass the media type with the response:

@app.get("/workorders/attachment/{attachmentStoredFilename}")
async def get_work_order_attachment(attachmentStoredFilename: str):
    drive_streaming_body = deta_drive.download_file(attachmentStoredFilename)
    
    return StreamingResponse(drive_streaming_body.iter_chunks(), media_type="image/png")

from deta-python.

timbusfield avatar timbusfield commented on August 20, 2024

Thanks very much, I'll make sure I capture the UploadFile.content_type when the file is uploaded so that I can pass it to the StreamingResponse as the media_type when it is downloaded later

from deta-python.

abdelhai avatar abdelhai commented on August 20, 2024

@timbusfield you could easily get the media type on the fly from the file's extension. Look at this simple example:

https://github.com/abdelhai/drive-starter-python/blob/d71b25d68e81855b8d529e0a6b53991e2e05686f/main.py#L19..L22

from deta-python.

Related Issues (20)

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.