I am having trouble uploading multiple file to different urls using ng2-file-upload method
.
I am using this repo https://github.com/valor-software/ng2-file-upload
to make this. ng2-file-upload
is easily integrated in my app using this demo to upload files. Also, they provided a method to upload multiple files on a particular url.
But I want to upload different files at different url
, which I am not able to find out yet.
// sample code
import { Component } from '@angular/core';
import { FileUploader } from 'ng2-file-upload';
const URL = '/api/some_url';
@Component({
selector: 'simple-demo',
templateUrl: './simple-demo.html'
})
export class SimpleDemoComponent {
public uploader:FileUploader = new FileUploader({url: URL}); // here to add url
}
This FileUploader
provides way to give url
to upload file. Usefulness of this method is that, progress-bar
and related feature are integrated with this ng2-file-uploader
component. I have searched a lot but not able to find any solution to upload to different urls.
Any useful suggestion will be appreciated!!
Here is how i was able to do the same. You would have to override onBeforeUploadItem of the uploader.
define:
this.uploader = new FileUploader({url: this.uploadUrl});
in the constructor
this.uploader.onBeforeUploadItem = (fileItem: FileItem): any => {
// logic of connecting url with the file
fileItem.url = 'http://localhost:3001/path/v1';
return {fileItem};
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With