0

I am using the ng2-file-upload plugin to upload my files But when I upload a file it changes the file name and saves different file name in the database, is there a way to get the Original file name. I need to show the original name of the file in my view.

Link to plugin= https://www.npmjs.com/package/ng2-file-upload

2 Answers2

0

If Someone else faces this problem then I am posting my code for your help. my input element just ignores parameter "31" I am using it for something else. you just need to pass $event in the parameter.

<input type="file" ng2FileSelect [uploader]="uploader" placeholder="{{'SALONPROFILE.Trading-Image-Url' | translate}}" (change)="uploadFiles(31,$event)"  name="TradingImageUrl" />

This is my function in component and i am saving orignal file name in local variable this.filenName,and good thing is it is saving orignal name.

    uploadFiles(categoryId: number, $event: any) {
    this.uploader.options.additionalParameter = {
        filecategoryId: categoryId,         
    };
    this.filename= $event.target.files[0].name;
    this.uploader.uploadAll();
}
0

You could also get file name before upload. For this FileUploader has onBeforeUploadItem hook.

Example: I would like to send fileName to server and change URL before sending

const uploader = new FileUploader({
    // options
    url: 'api/files'
});

uploader.onBeforeUploadItem = (item: FileItem) => changeBeforeUpload(item);

const changeBeforeUpload = (item: FileItem) => {
    item.url = `${item.url}/${item.file.name}`;
}
Avinash Singh
  • 4,970
  • 8
  • 20
  • 35
Evgeniy Boytsov
  • 214
  • 2
  • 8