vendredi 4 octobre 2019

download file FROM web TO flask server

My flask app should download files from urls which are posted to my app by a json object. The files should be downloaded for further processing. I do not get an error message. A lot of tutorials are about how a user uploads a file, but this is not my case. Can anyone help?

import os


from flask import Flask, request, jsonify
import urllib.request as web

app = Flask(__name__)
download_folder=os.path.join(app.instance_path,'downloads')
app.config['DOWNLOAD_FOLDER'] = download_folder


@app.route('/syncaudio', methods=['POST'])
def syncaudio():
    files = request.get_json(force=True)

    for file_url in files['syncFileUrls']:
        local_file = os.path.join(app.config['DOWNLOAD_FOLDER'],file.rsplit('/')[-1])
        web.urlretrieve(file_url,local_file)


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



Aucun commentaire:

Enregistrer un commentaire