[FIXED] How to use PrimeNG p-fileUpload without multipart/form-data?


I’m using p-fileUpload to upload a .zip file into AWS S3, the upload works and I can download and open the file correctly by the OS application, but when I tried to read the same file using an InputStream Java, it doesn’t work so well, e.g.

try (InputStream in = new URL(uri).openStream()) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(in, out);

        return ByteBuffer.wrap(out.toByteArray());
    } catch (IOException ex) {
        throw new SomeException(ex);

Inspecting the file I see the following data:

Content-Disposition: form-data; name="MyAwesomeFunction970"; filename="hello-lambda.zip"
Content-Type: application/zip



The data above has some headers information and things that seems to be part of a multipart/form-data upload.

If I put the file through Postman, for example, the data is a little different (without the headers) and then works well via InputStream Java code.


Anyone knows what’s happening with the upload process and how to fix it?


I figured out this problem by calling a custom upload method, e.g:

    (uploadHandler)="customUpload($event.files, uploadUrl)">

customUpload(files:any, uploadUrl:string) {
    var reader = new FileReader();
    reader.onload = function (evt) {
        var xhr = new XMLHttpRequest();
        xhr.open('PUT', uploadUrl, true);
        xhr.setRequestHeader('Content-Type', files[0].type);

Answered By – Luan Kevin Ferreira

Answer Checked By – Timothy Miller (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published