1

I am trying to send a static file through flask based on the user call by using the send_file method. The method keeps giving me a 200 message, but on the js file, keeps coming up as an error despite the 200. Here is the python code and the error message:

@custom_code.route('/get_data', methods=['POST'])
def get_mnist_data():
    index = int(request.form['index'])
    return send_file('static/stims/'+index, attachment_filename='image.png')

error message can't be copied and pasted, but it says: readyState:4, responseText: and a bunch of symbols that look like \u0000 status:200 statusText:OK

Thank you for the other response, but the difference between that and mine is that I am trying to make an ajax call to get an image from a static location and then have it displayed on the given image slot on the html file, similar to a photo album on facebook or flickr, rather than downloading the file. Would really appreciate any advice. Thanks

aimf212
  • 39
  • 5

1 Answers1

0

Does it help if you change your return, and add the as_attachment = True to that specific line?

return send_file('static/stims/'+index, as_attachment = True, attachment_filename='image.png')
gittert
  • 1,238
  • 2
  • 7
  • 15
  • no, i tried and still get the same error – aimf212 Aug 30 '18 at 14:53
  • Try to print index to console to see what it is. And try download a file with complete and correct link in send_file function, without index as variable. Try to find out what is causing the error message. It would be most helpful to see the actual error message. I'm sure copy paste is possible. – gittert Aug 30 '18 at 16:13