Flask download binary file






















This file should be created under the project root directory. Notice how I create flask instance. Next I will create main. In the above source code, the root path or endpoint will simply render the UI. This UI contains only one link for downloading a file from the server. Clicking on the link will ask user to save the file in a chosen location. The file type could be anything. And that's all the coding we need. Otherwise it will return the JSON data as by default.

There's an xml example on github. I know this question was asked 7 years ago so it probably doesn't matter any more to Ayrx. Hope it helps to whoever drops by.

As long as you're setting the Content-Type header accordingly and respecting the Accept header sent by the client, you're free to return any format you want. After lot of trials and experiments, including hours of browsing to make the Response class as Single Responsible down loader. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. BytesIO img. Hafizur Rahman Hafizur Rahman 1, 17 17 silver badges 28 28 bronze badges. Using this code on the server side, how I can I decode it in javascript? Encode the string as ascii then decode the bytes as base 64 and save it as an image?

Did you try: 1. Hello, is there a way you could update to reflect showing the js part? The conversion can be shown in the form of an example image that was read and converted to base64 format and then back to original. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. If you select a file and upload it, you should have the file uploaded in the media folder of the django server.

In this tutorial, you've seen how you can use Python and the requests library to upload a file from a server to another server. In case your file is static, search for how to configure Flask to serve static files.

These shall be automatically served in streaming manner. Assuming, the file is static, you shall in production serve it by reverse proxy in front of your Flask app. This not only offloads your app, but also works much faster. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.

Learn more. Asked 7 years, 6 months ago. Active 7 years, 6 months ago.



0コメント

  • 1000 / 1000