Note that there are some explanatory texts on larger screens.

plurals
  1. PORight click, "save image as" is not working for dynamically generated PIL image (Flask)
    primarykey
    data
    text
    <p>I have some experience with Python but none with Flask or any web development. I tried deploying my first app on PythonAnywhere using Flask. It's a very simple script and the "desktop" version works perfectly well. On the site, the image is being generated and saved to file in a static folder ('/static/').</p> <p>I want the script to show the user the picture automatically once it is generated. The most important thing is that the user must be able to save it. However, when I try:</p> <pre><code>return redirect("http://www.example.com/static/image.png") </code></pre> <p>the image is being displayed properly and can be saved properly using "Save Page as". But when I right click the image and click "save image as", the file it writes is corrupted. It's not even the image (the file size is much larger). The filename is wrong too. Instead of "image.png" it saves it as "enc_text.png" ("enc_text" is the name of the function in my script.</p> <p>How can I get "save image" to work?</p> <p>(I don't want a solution to do with embedding the image on a blank HTML page (e.g., img src="...")</p> <p>Any help is much appreciated.</p> <p><strong>EDIT</strong></p> <pre><code>@app.route('/enc_text', methods=['POST']) def enc_text(): text = request.form['text'] text = unidecode.unidecode(text) filepath = os.path.join(app.config['UPLOAD_FOLDER'],'steg','enc') filename = 'image.txt' targetname = filename.rsplit('.', 1)[0] + '.png' target = os.path.join(app.config['UPLOAD_FOLDER'],'steg','enc',targetname) steg.encode(text, target) #Reads text and returns PNG file return redirect("http://www.mysite.com/static/image.png") </code></pre> <p>(Note: steg.encode is a function I wrote)</p> <p><strong>EDIT</strong></p> <p>It seems to be only a problem with Firefox (23.0.1). The problem persists even when I restart Firefox in Safe Mode. I tried it on IE, Chrome and Safari and both "Save page" and "Save image" works fine. That's weird. I opened the "enc_text.png" using notepad and it contains the following HTML:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"&gt; &lt;title&gt;405 Method Not Allowed&lt;/title&gt; &lt;h1&gt;Method Not Allowed&lt;/h1&gt; &lt;p&gt;The method is not allowed for the requested URL.&lt;/p&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload