Base solution for your next web application
Open Closed

How to set the formData before upload file #9185


User avatar
0
Simonlum created

Hello support team! I'm using the PrimeNG upload componet and i want to set custom parameters in formdata before upload; i'm using the events onSend or onBeforeUpoad but it does not work; So how can i do it?

below is my code:

    onBeforeSend(event): void {
        // tslint:disable-next-line:no-debugger
        debugger;
        //event.xhr.setRequestHeader('Authorization', 'Bearer ' + abp.auth.getToken());
        //event.xhr.addRequestHeader('Access-Control-Allow-Origin', '*');
        event.formData.append('UploadFolder', 'Customer');
        //let ob = this;

    }
    
     <p-fileUpload mode="basic" [chooseLabel]="l('ChoosePicture')"
                                    name="businessLicenseFileInput[]" [url]="uploadUrl" maxFileSize="5242880"
                                    (onUpload)="businessLicenseOnUpload($event)"
                                    (onSend)="onBeforeSend($event)">
     </p-fileUpload>
     
     the server code:
     
       var files = Request.Form.Files;
                string type = Request.Form["UploadFolder"];
                //Check input
                if (files == null)
                {
                    throw new UserFriendlyException(L("File_Empty_Error"));
                }

3 Answer(s)
  • User Avatar
    1
    musa.demir created

    onBeforeSend might work, can you please check that https://stackoverflow.com/a/45203011/9988758

  • User Avatar
    0
    Simonlum created

    I used the primeNG 9.03 in my project and the primeNG removed the event onBeforeSend after version 9+;

    Is there any other way to solve this problem ? thanks!

    "primeicons": "^2.0.0",
    "primeng": "^9.0.3",
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can use uploadHandler like this