silkimen / cordova-plugin-advanced-http

Cordova / Phonegap plugin for communicating with HTTP servers. Allows for SSL pinning!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't get a Blob with sendRequest function

Homand-Cindy opened this issue · comments

I use the sendRequest function to downloading a PDF in Ionic App. I am sending the responseType= "blob" but the response value is always text. If i convert the response value to Blob and I read this in PDFViewer, the PDF is corrupted.

import { HTTP, HTTPResponse } from '@ionic-native/http/ngx';
...
public adHTTP: HTTP
...

let res : HTTPResponse = await this.adHTTP.sendRequest("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf", {method: "get", responseType: "blob"});
console.log(res.data); // res.data is not Blob but is Text 

let blobresp: Blob = new Blob([res.data], {type: "application/pdf"});
console.log(blobresp); // is I use the Blob in PdfViewer, I have an error "PDF is corrupted"

Thanks for your help!!!

Hi Homand-Cindy, I think your problem is that you try to create a Blob manually. response.data will be a Blob instance already when you set the responseType accordingly.

Hello,

Thank you for the answer.
I put responseType: "blob" in the SendRequest function call but res.data returns text and not a blob. That's my problem and that's why I tried to convert it manually to blob.
I don't understand why res.data is not a blob instance when I ask it a responseType: "blob". Did I forget something?

Thanks in advance.

Hmm I just tried to check the ionic-native wrapper code and found out that the ionic team decided not to support it anymore. Daniel Sogl is taking over the code and it's renamed to "awesome-cordova-plugins". The interface defined awesome-cordova-plugins/plugins/http/index.ts seems very odd to me. It doesn't really match the interface of this plugin. Someone should check that and fix it. Maybe your problem is related to that? I'm not sure tbh.

Closing this, feel free to open a new issue, if this won't solve your problem! 👍