Custom response type #1182

Open
opened 2021-09-02 15:15:03 +00:00 by apseftis86 · 3 comments
apseftis86 commented 2021-09-02 15:15:03 +00:00 (Migrated from github.com)

I am working on something that will take a .zip file, transform it on a backend server , and then send back its contents to the user as a .zip.

I have found that I can do this outside of the FileUploader so that is an option but since the FileUploader is what I am using for the drag and drop and sending I was hoping there was a way I could incorporate this last part into my code.

Basically I need the response type to be 'blob' and right now it comes back as a string. Is there any way I am able to change what the response type is?

I am working on something that will take a .zip file, transform it on a backend server , and then send back its contents to the user as a .zip. I have found that I can do this outside of the FileUploader so that is an option but since the FileUploader is what I am using for the drag and drop and sending I was hoping there was a way I could incorporate this last part into my code. Basically I need the response type to be 'blob' and right now it comes back as a string. Is there any way I am able to change what the response type is?
apseftis86 commented 2021-09-08 12:11:04 +00:00 (Migrated from github.com)

I was able to solve the first part of my problem with another issue listed here but now even though it works it does log an error in the console. Perhaps theres a way to add to the function to skip over this error?

Screen Shot 2021-09-07 at 6 20 53 PM
I was able to solve the first part of my problem with another issue listed here but now even though it works it does log an error in the console. Perhaps theres a way to add to the function to skip over this error? <img width="663" alt="Screen Shot 2021-09-07 at 6 20 53 PM" src="https://user-images.githubusercontent.com/32655883/132505961-0948160c-a4a9-4cfe-abe3-3d3a1937d98e.png">
apseftis86 commented 2021-09-08 16:02:29 +00:00 (Migrated from github.com)

So, to solve it myself in the meantime I changed the code to my own module:

inside of the _xhrTransport function:

if (xhr.readyState === XMLHttpRequest.DONE) {
  that.response.emit(xhr.responseText);
}

to:

  if (xhr.readyState === XMLHttpRequest.DONE) {
    that.response.emit(xhr.response);
   }

and added the following to the uploader

this.uploader.onBeforeUploadItem = (item: CustomFileItem) => {
  item._xhr.responseType = 'blob';
};
So, to solve it myself in the meantime I changed the code to my own module: inside of the _xhrTransport function: ``` if (xhr.readyState === XMLHttpRequest.DONE) { that.response.emit(xhr.responseText); } ``` to: ``` if (xhr.readyState === XMLHttpRequest.DONE) { that.response.emit(xhr.response); } ``` and added the following to the uploader ``` this.uploader.onBeforeUploadItem = (item: CustomFileItem) => { item._xhr.responseType = 'blob'; }; ```
apseftis86 commented 2021-09-08 16:49:48 +00:00 (Migrated from github.com)

Looking at the documentation for XMLHttpRequest doing it the way I changed it to is the preferred method now anyways.

Screen Shot 2021-09-08 at 12 44 49 PM

Source: https://javascript.info/xmlhttprequest#response-type

Looking at the documentation for XMLHttpRequest doing it the way I changed it to is the preferred method now anyways. <img width="824" alt="Screen Shot 2021-09-08 at 12 44 49 PM" src="https://user-images.githubusercontent.com/32655883/132551173-f99e0935-6a2c-46c7-bcf2-424b17bd9e7f.png"> **Source**: https://javascript.info/xmlhttprequest#response-type
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#1182