How to get the data after upload #1152

Open
opened 2020-05-21 20:00:55 +00:00 by GYahia · 0 comments
GYahia commented 2020-05-21 20:00:55 +00:00 (Migrated from github.com)

Hi everyone, after I upload my file I would like to extract the data so that I can use it later.
So this is the code I am using, works great for everything except what I mentionned above.

  export class FileUploadComponent implements OnInit {
  uploadForm: FormGroup;
  public uploader: FileUploader = new FileUploader({});
  constructor(private formBuilder: FormBuilder, private managerService: ManagerService) { }

uploadSubmit() {

let fileItem = this.uploader.queue[0]._file;
if (fileItem.size > 10000000) {
  alert("Les fichiers ne doivent pas dépasser 10MB.");
  return;
}

let data = new FormData();

console.log(fileItem.name);
data.append('file', fileItem);
data.append('dataType', this.uploadForm.controls.type.value);
this.uploader.onAfterAddingFile = (fileItem) => {
  console.log(fileItem);//Will print file data included created file
};
this.managerService.uploadFile(data).subscribe(() => alert("Import réalisé avec succès!"));

this.uploader.clearQueue();


}
ngOnInit() {
this.uploadForm = this.formBuilder.group({
  document: [null, null],
  type: [null, Validators.compose([Validators.required])]
});
this.uploader.onAfterAddingFile = f => {
  if (this.uploader.queue.length > 1) {
    this.uploader.removeFromQueue(this.uploader.queue[0]);
  }
   }

 }

}`

What am I missing here?
and what could be the best way to export the data to a datable like ag-grid?

Hi everyone, after I upload my file I would like to extract the data so that I can use it later. So this is the code I am using, works great for everything except what I mentionned above. export class FileUploadComponent implements OnInit { uploadForm: FormGroup; public uploader: FileUploader = new FileUploader({}); constructor(private formBuilder: FormBuilder, private managerService: ManagerService) { } uploadSubmit() { let fileItem = this.uploader.queue[0]._file; if (fileItem.size > 10000000) { alert("Les fichiers ne doivent pas dépasser 10MB."); return; } let data = new FormData(); console.log(fileItem.name); data.append('file', fileItem); data.append('dataType', this.uploadForm.controls.type.value); this.uploader.onAfterAddingFile = (fileItem) => { console.log(fileItem);//Will print file data included created file }; this.managerService.uploadFile(data).subscribe(() => alert("Import réalisé avec succès!")); this.uploader.clearQueue(); } ngOnInit() { this.uploadForm = this.formBuilder.group({ document: [null, null], type: [null, Validators.compose([Validators.required])] }); this.uploader.onAfterAddingFile = f => { if (this.uploader.queue.length > 1) { this.uploader.removeFromQueue(this.uploader.queue[0]); } } } }` What am I missing here? and what could be the best way to export the data to a datable like ag-grid?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#1152