sparckles / Robyn

Robyn is a Super Fast Async Python Web Framework with a Rust runtime.
https://robyn.tech/
BSD 2-Clause "Simplified" License
3.89k stars 195 forks source link

A file serve Download bug. #876

Open asamaayako opened 2 days ago

asamaayako commented 2 days ago

Bug Description

response a .wav file . The downloaded file is corrupted. source size is 4.45 MB (4,671,364 bytes). but download file has become 7.84 MB (8,229,002 bytes).

test code

import os
import pathlib

from robyn import Robyn, serve_file

app = Robyn(__name__)

current_file_path = pathlib.Path(__file__).parent.resolve()

@app.get("/")
def hello_world():
    file_path = os.path.join(current_file_path, "source.wav")  #a audio file
    return serve_file(file_path)

if __name__ == "__main__":
    app.start()

Steps to Reproduce

No response

Your operating system

Windows

Your Python version (python --version)

3.11

Your Robyn version

latest

Additional Info

the console output Robyn version: 0.56.0. I just use pip install this project

sansyrox commented 1 day ago

Hey @asamaayako 👋 Thanks for reporting this. I will investigate tonight 😊

asamaayako commented 1 day ago

Hey @sansyrox 👋 I think It's not filename missing problem. My description seems inadequate, Even using the following code, file will still be corrupted, The reason is similar to #874 I think. Response does a conversion of all returned body data.

@app.get("/")
def getwav():
    return FileResponse("source/test.wav", #a audio file
                        headers=Headers({
                        "Content-Disposition": "attachment; filename=d.wav",
                        "Content-Type": "audio/wav",
    }))