valor-software / ng2-file-upload

Easy to use Angular components for files upload
http://valor-software.github.io/ng2-file-upload/
MIT License
1.91k stars 662 forks source link

Using ng2-file-upload with Flask python #968

Closed MehdiBenHamida closed 2 years ago

MehdiBenHamida commented 6 years ago

I do not have an idea how to upload a file to Flask Python server using ng2-file-upload with Angular2. I don't know how to pass a Flask Python url to FileUploader.

I am trying to find something on internet about this, but nothing until now.

How can I develop an ng2-file-upload back-end side with Flask python?

emishaikh commented 6 years ago

in the angular part use this.

URL = 'http://localhost:3000/upload'; constructor(private router:Router, private ocrService:OcrServiceService) {

this.uploader= new FileUploader({ url: this.URL});

this.uploader.onCompleteItem = (item:any, response:any, status:any, headers:any) => {
  this.fileurl = response
  console.log(response)
};

}

where url will the api , where you want to savesend that file for backend, and in flask

showing Result Routes

cwd = os.getcwd() dir = './uploads'

@default.route('/upload', methods=['POST', 'OPTIONS']) @crossdomain(origin='http://localhost:4200', headers='X-Requested-With,content-type') def upload(): if request.method == 'POST': file = request.files['file'] filename = secure_filename(file.filename) file.save(os.path.join(dir,filename))

where dir will the folder , where you want to save the file.

schandrakandi commented 6 years ago

Do we know how we do upload for the flask server ?

schandrakandi commented 6 years ago

@MehdiBenHamida Did you find any way to do this ?

MehdiBenHamida commented 6 years ago

@schandrakandi did you try the solution suggested by @emishaikh ?