FileUpload (p-fileUpload) read files data after posting it to controller
Hi again,
<p-fileUpload name="files[]" url="{{serviceUrl}}" (onUpload)="onFileUpload($event)" (onSelect)="onFileSelect($event)" multiple="multiple" maxFileSize="10485760"
[ngModelOptions]="{standalone: true}" (onBeforeUpload)="onBeforeFileUpload($event)" (onError)="onFileUploadError($event)"
invalidFileSizeMessageSummary="{{'FILE_IS_TO_BIG' | translate}}" invalidFileSizeMessageDetail="{{'MAX_FILE_SIZE' | translate}}"></p-fileUpload>
looking for help with reading files data sent by fileupload cntrl. Im currently trying to access files in controller, but first of all I dont know where files should be passed in Http requests. Was trying with:
var sth = await new StreamReader(Request.Body).ReadToEndAsync(); but this gives me only 1 file (Im using multiupload option). And honeslty speaking dunno if that is correct data cuz properties like Request.Body.Length throws an error: Length = '((Microsoft.AspNetCore.Server.Kestrel.Internal.Http.FrameRequestStream)Request.Body).Length' threw an exception of type 'System.NotSupportedException'
My second apporach was to access Http.Request.Form, but here I get face-punch : 'Form = '((Microsoft.AspNetCore.Http.Internal.DefaultHttpRequest)Request).Form' threw an exception of type 'System.InvalidOperationException'
On component side in onBeforeUpload event was trying to use different encryptions event.xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); event.xhr.setRequestHeader("Content-Type", "multipart/form-data"/);
but still with no luck.
Will be very gratefull for any help cuz right now I dont know if I'm missing sth or fileupload has some error with angular2 (2.0.1) and .Net Core (1.0.0-preview2-003131). Currently using: "primeng": "1.0.0-rc.3",
OK, I figure it out. I removed line with setting content-type in onBeforeFileUpload event
onBeforeFileUpload(event: any) { let authToken = this.authService.getToken(); this.slimLoader.start(); event.xhr.setRequestHeader("Authorization", "Bearer " + authToken); //event.xhr.setRequestHeader("Content-Type", "multipart/form-data"); }
and in controller in action method I accept ICollection[HttpPost] public async Task<IActionResult> AddFuellingRequestFile(ICollection<IFormFile> files) { ServiceResult<bool> result = await Task.Run(() => ServiceResult<bool>.Ok(true)); }
So leaving this comment - maybe will be helpfull 4 others. cheers