0

Context

I created a python flask restful service to interact with my MySQL database. I just added a new path to get images and to save it. It works when I tested it with python requests library but I have no idea how to implement this into html and AJAX javascript.

What I Tried

  • I tried to simply google my question in different ways of phrasing it and whatnot but I couldn't find anything useful

What i'm expecting at the end

I simply want to be able to send an image from html webpage to my flask server and have It save the file.


Code

Python code

class process_image(Resource):
    def post(self):
        file = request.files['image']

        file.save('thephotisdfhghdfghfgh.jpg')

        return(200)
api.add_resource(process_image, '/image')


if __name__ == '__main__':
    app.run(debug=True)

Request command

url = 'http://127.0.0.1:5000/image'
my_img = {'image': open('test.jpg', 'rb')}
r = requests.post(url, files=my_img)
Phil
  • 157,677
  • 23
  • 242
  • 245
Caminero
  • 265
  • 3
  • 19

0 Answers0