1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python Flask server code receiving a XHR send POST request image and save it under...

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    Python Flask server code receiving a XHR send POST request image and want to save it. This is the following code as I send the picture thru the web portal:

    document.getElementById('file-image').src = URL.createObjectURL(file);


    in which will generate the corresponding blob image link as following:

    blob:http://127.0.0.1:8080/f4bbec18-31b4-4d5b-b265-409142397ac5

    And my header of the request would be like following,

    xhr.open('POST', document.getElementById('file-upload-form').action, true);
    xhr.setRequestHeader('X-File-Name', file.name);
    xhr.setRequestHeader('X-File-Size', file.size);
    xhr.setRequestHeader('file-url', document.getElementById('file-image').src);
    xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
    xhr.setRequestHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    xhr.setRequestHeader('Content-Type', 'multipart/form-data');
    xhr.send(file);


    Now, inside my python flask server, I want to process that "POST" request and save the image into folder:

    @app.route('/cv',methods=['POST'])
    def getpic():
    print(request.headers.get('file-url'))



    Now I want to ask, how can I save the blob linked image and process it.

    I am sure that I can see the image as I paste the link to browser as following

    [​IMG]

    Thanks,

    Toby.

    Continue reading...

Compartilhe esta Página