Extract file from file storage object in flask

I am learning how to work with file uploads in flask. Earlier from here, i worked with pdf file uploads and read the contents of it. This happens inside client.py file.

Now i would like to pass my file from client to server that is running locally. When i use request.file, it will get it as FileStorage Object. So, without saving or providing file path, i want to upload file from client and pass it to the server to do further process.

class mainSessRunning():
     def proces(input):
     return result

run = mainSessRunning()

@app.route('/input', methods=['POST'])
def input():
    input_file = request.files['file']
   ...(extract file from filestorage object "input_file")...
    result = run.process(file) ## process is user defined function 
    return (result)

here i want to send the incoming file through process() function to server running locally. How do i do this? I came across same question but couldn't able to find anything

1 answer

  • answered 2018-04-17 06:23 Sraw

    What do you mean "extract"? If you want get the bytes of file, you can use content = request.files['file'].read().

    And then send this content to any where you want: res = requests.post(url, content)