How can I send additional parameters via ng2-file-upload when I upload a file

1.5k Views Asked by At

I have created two selects and want to send their values as parameters to the backend during upload. Do you know how to do that? Can you help me please?

My Code:

// Select Forms
 // Month form
    this.sendMonthsForm = this.fb.group({
      monthsValue: [null]
    });
    // Year form
    this.sendYearsForm = this.fb.group({
      yearsValue: [null]
    });
// Upload
  this.uploader = new FileUploader({
        url: `${environment.baseUrl}/upload?title=SuSa&context=${year}&period=${month}`,
        maxFileSize: 2 * 1024 * 1024,
        allowedFileType: ['csv', 'xls', 'xlsx'],
        authToken: `Bearer ${currentUser.auth_token}`,
      });
2

There are 2 best solutions below

0
Santhosh V On
uploader: FileUploader = new FileUploader({
  url: URL,
  headers: [{ name: 'Authorization', value: 'Bearer ejy...' }]
});
0
gowtham On
this.uploader = new FileUploader({
        url: `${environment.baseUrl}/upload?title=SuSa&context=${year}&period=${month}`,
        maxFileSize: 2 * 1024 * 1024,
        additionalParameter:{uploaderparams1:'its-value',uploaderparams2:'its-value'},
        allowedFileType: ['csv', 'xls', 'xlsx'],
        authToken: `Bearer ${currentUser.auth_token}`,
      });