How to open Blob URL on Chrome iOS

后端 未结 3 1759
天命终不由人
天命终不由人 2020-12-01 04:33

I\'d like to open Blob object in a browser window.

This code works everywhere but iOS Chrome (and IE of course but I can solve IE). The window is not redirected to

相关标签:
3条回答
  • 2020-12-01 05:05

    FileReader.readAsBinaryString method has been deprecated.

    Bit late, but I had todo something similar using the FileReader.readAsDataURL - which produces a dataUrl. I'm using AngularJS $http service to call the API to create a pdf. Hope this helps, see below:

    $http.post('/api/pdf', {id: '123'}, {responseType: 'arraybuffer'})
        .success(function (response) {
            var blob = new Blob([response.data], {type: 'application/pdf'});
            var reader = new FileReader();
            reader.onloadend = function(e) {
                 $window.open(reader.result);
            }
            reader.readAsDataURL(blob);
        });
    
    0 讨论(0)
  • 2020-12-01 05:13

    FileReader solved my problem.

    var reader = new FileReader();
    var out = new Blob([this.response], {type: 'application/pdf'});
    reader.onload = function(e){
      window.location.href = reader.result;
    }
    reader.readAsDataURL(out);
    
    0 讨论(0)
  • 2020-12-01 05:24

    I fixed it by changing content-type from application/json to application/octet-stream. My xlsx file was downloaded as json.

    @PostMapping(value = "/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)

    0 讨论(0)
提交回复
热议问题