After downloading an image from google drive using the google drive API, In response what i get is a PNG Chunks text of my downloaded image. But, I could't get the png file from that text. How can i convert it to a PNG by javaScript?
// google drive download file function
function downloadFile(Url, callback) {
console.log("download url-->",file.downloadUrl)
// if (file.downloadUrl)
if (Url)
{
var accessToken = gapi.auth.getToken().access_token;
var xhr = new XMLHttpRequest();
// xhr.open('GET', file.downloadUrl);
xhr.open('GET',Url);
xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
xhr.onload = function() {
callback(xhr.responseText);
};
xhr.onerror = function() {
callback(null);
};
xhr.send();
} else {
callback(null);
}
}
downloadFile("https://www.googleapis.com/drive/v2/files/id?alt=media&source=downloadUrl",
function(resp){
console.log("resp",resp)
})