Hello, i have big problem with a module of my app, i need to upload an array of files from my app like this way:
By the side of ionic i use this:
My provider method that get the local system url
resolveLocalUri(filePath:any){
return this.file.resolveLocalFilesystemUrl(filePath)
}
By the sife of my page i convert each photo to file
for(var k = 0 ; k < this.photos.length; k++){
var filePhoto = (<FileEntry>await this.nativeProvider.resolveLocalUri(this.photos[k]))
filePhoto.file(file=>{
this.files.push(file)
})
}
My uploader service
const formData = new FormData();
let headers = new HttpHeaders();
headers = headers.append('Authorization',token)
//const reader = new FileReader();
//reader.onloadend = ()=>{
for(let i = 0; i < files.length; i++){
formData.append(fileKey, files[i], files[i]['name'])
}
//}
return this.http.post(this.url+params,formData,{headers:headers})
But nothing
Some help please
Does it need to be done in a form?
I am using ng2-file-upload with success with multer.
Here is an older post with working solution that I still use today with some modifications.
You could like skip a lot of the UI and just have one upload button.
Here is a brief description of what is working for me. Feel free to improve:
( I have skipped the authorization requirements )
In my Component:
import { FileSelectDirective, FileDropDirective, FileUploader } from '../../../node_modules/ng2-file-upload';
const URL = 'https://locationofyourserverandapiendpoint';
export class Page1 {
uploader:FileUploader;
hasBaseDropZoneOver:boolean;
hasAnotherDropZoneOver:boolean;
public fileOverBase(e:any):void {
this.hasBaseDropZoneOver = e;
}…
Thank you, i have the idea with this dependency but i don’t know where to put exactly my array of files, i look at the addToQueue function but it makes a multiple call to our back end, on my case i need only one request with an array of objects
This is what i have until now on my service:
uploadData(files:any,fileKey:any,params:any,token:any):FileUploader{
this.uploader = new FileUploader(
{
url:this.url+params,
authTokenHeader:'Authorization',
authToken: token
}
)
this.uploader.onBuildItemForm = (item, form) => {
form.append(fileKey, files);
item.upload()
};
console.log(this.uploader)
return this.uploader
}
Thank you …
Yes, that loops through the queue and uploads one at a time.
I do not personally upload as an array but here is some potential for you: