1

ANGULAR

public uploadFile(file:any) {
    debugger;
    var body = {user_id: localStorage.getItem('userID')};
     var formData = new FormData();
     formData.append('file', file[0]);
     formData.append('user_id', localStorage.getItem('userID'));


    const path = this.endpoint + `/jotpegie`;
    const headers = new Headers({ 'Content-Type': 'application/json' });
  //  const options = new RequestOptions({ headers: headers });
    var options = { content: formData, model:body};
    return this.http.post(path, formData, options);
}

FLASK Here I would like to extract posted file and json with data (data[user_id]). I was trying to use request.get_json() but it didn't work. Thank you in advance for your help.

@geotiff_blueprint.route("/jotpegie", methods=['GET', 'POST'])
def jotpegie():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and ".jpg" in file.filename:
            raw_path = secure_filename(file.filename)
            file.save(raw_path)
            return start_processing_file(raw_path, data[user_id])
    return
Scimon
  • 11
  • 2

0 Answers0