-1

Hey everyone now I can send img from android to flask sever done. code by ahmedfgad/AndroidFlask but how to retrieve img back

in flask sever [python]

import flask
import werkzeug
import time
import os
app = flask.Flask(__name__)    
from readFileLastest import newest    

@app.route('/', methods = ['GET', 'POST'])
def handle_request():
    n = 0
    files_ids = list(flask.request.files)
    print("\nNumber of Received Images : ", len(files_ids))
    image_num = 1
    for file_id in files_ids:
        print("\nSaving Image ", str(image_num), "/", len(files_ids))
        imagefile = flask.request.files[file_id]
        filename = werkzeug.utils.secure_filename(imagefile.filename)
        print("Image Filename : " + imagefile.filename)
        timestr = time.strftime("%Y%m%d-%H%M%S")
        path = r'C:\Users\User\Desktop\AndroidFlask-master\Part 1\FlaskServer\uploads'
        imagefile.save(os.path.join(path,filename))     

        image_num = image_num + 1

    print("\n")    

    return "Image(s) Uploaded Successfully. Come Back Soon."

app.run(host="0.0.0.0", port=8888, debug=True)

1 Answers1

1

You can use send_file to return a file from flask. For an image, use mimetype='image/gif'. Something like this:

from flask import send_file

@app.route('/get_image')
def get_image():
    # your code here
    return send_file(filename, mimetype='image/gif')

Hope this helps. Good luck.

Harshal Parekh
  • 5,918
  • 4
  • 21
  • 43