0

Hi I'm tired after trying each solution but not able to make it work.

my http call in angular is

$http({
  method: 'GET',
  url: API_URL + 'v1/file/' + candidateId + '/download',
  headers: {
    'authToken': AuthService.getToken(),
  },
  responseType: 'arraybuffer'
})
.then(function onSuccess(response) {
  successCallback(response);
},
function onError(response) {
  errorCallback(response);
});

and in Success of this code

vm.onSuccessDownloadResume = function(response) {
  var blob = new Blob([response.data], {type: response.headers('content-type')});
  var objectUrl = URL.createObjectURL(blob);
  window.open(objectUrl);
};

I tried webkitURL.createObjectURL(blob), it's working fine for chrome only but URL.createObject is not at all working.

getting message URL.createObjectURL() is not a function()

Thanks

Khilen Maniyar
  • 2,519
  • 7
  • 31
  • 35

1 Answers1

0

There's some compatibility issues related to createObjectURL, you can see more here: https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

And with Blob: https://developer.mozilla.org/en-US/docs/Web/API/BlobBuilder#Browser_compatibility

I had a similar issue, and this SO link helped me with a workaround: Blob constructor browser compatibility

I've copied this function and made some minor changes:

var NewBlob = function(data, datatype)
{
    var out;

    try {
        out = new Blob([data], {type: datatype});
        console.debug("case 1");
    }
    catch (e) {
        window.BlobBuilder = window.BlobBuilder ||
                window.WebKitBlobBuilder ||
                window.MozBlobBuilder ||
                window.MSBlobBuilder;

        if (e.name == 'TypeError' && window.BlobBuilder) {
            var bb = new BlobBuilder();
            bb.append(data);
            out = bb.getBlob(datatype);
            console.debug("case 2");
        }
        else if (e.name == "InvalidStateError") {
            // InvalidStateError (tested on FF13 WinXP)
            out = new Blob([data], {type: datatype});
            console.debug("case 3");
        }
        else {
            // We're screwed, blob constructor unsupported entirely   
            console.debug("Errore");
        }
    }
    return out;
}
Community
  • 1
  • 1
Ricardo Pontual
  • 3,749
  • 3
  • 28
  • 43