that on my local pc, returns a subtitle file. Whole subtitle is set to a string in the data variable. It has only 39kbs. But when I try to download it on my deployed app, I’m getting an empty file - 0b. In logs I can see content of the file.
If you are able to read the file and log contents on Vercel. It means that the file is available to the serverless function, so no issues there.
Without looking at the full code example, I think buffer.getvalue() should be able to get the full content. Can you try the following code changes once?
from flask import make_response
from io import BytesIO
from flask import Response
def return_srt_file(data, filename) -> Response:
if not data:
return make_response("No data to return", 400)
buffer = BytesIO()
buffer.write(data.encode("utf-8"))
buffer.seek(0)
resp = make_response(buffer.getvalue())
resp.headers["Content-Disposition"] = f"attachment; filename={filename}.srt"
resp.headers["Content-Type"] = "application/x-subrip"
resp.headers["Content-Length"] = str(len(data.encode("utf-8")))
return resp
If you need more help, please share your public repo or a minimal reproducible example. That will let us all work together from the same code to figure out what’s going wrong.
Thanks for taking some of your time to try to help me. I applied your code and deployed it. And now an example endpoint, that should return data (as it does locally) returns
No data to return
although I clearly see data in Vercel’s runtime logs ><
No. And I think I tried everything. What is interesting that if I provide smaller object for my function, it works just fine. But still, 32kb, it’s not mutch