content key is not throwing values inside data

2019-08-18 00:33发布

问题:

  • I am trying to download a pdf document.
  • but I am getting an error DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
  • if I debug my code I am getting undefined at the data.content console.log("data.content--->", data.content);
  • but when I open data I am seeing value in content. data: content: "JVBERi0xLjJ6DTEgMCBvYmoNPDwNL0NyZWF0b3IgKFZpc2lvbm" contentInfo: {id: "a2c93187-5422-46c7-bcf7-e663c28dcd2e", externalId: "PVDR-85-625", source: "PCM", fileType: "PDF", rcvdDttm: "2/6/2019 12:00:00 AM", …} message: "Content retrieved successfully" status: "ACCEPTED" __proto__: Object
  • is there anyway I am not accessing content key which is inside data.
  • I googled for the error and saw this fiddle.
  • my code is also similar to this fiddle http://jsfiddle.net/ovfiddle/7NqKb/ but still no luck in my code.
  • can you tell me how to fix it.
  • providing my code snippet, console and error below.
 getData(data) {
        console.log(data);
        console.log("data.content--->", data.content);
        var contentType = 'application/pdf';

        var b64Data = data.content;
        var blob = b64toBlob(b64Data, contentType);
        var blobUrl = URL.createObjectURL(blob);
        console.log("displayDocumentData blobUrl--->", blobUrl);
        window.location = blobUrl;
    }

console logs

{data: {…}, status: 200, statusText: "OK", headers: {…}, config: {…}, …}config: {adapter: ƒ, transformRequest: {…}, transformResponse: {…}, timeout: 0, xsrfCookieName: "XSRF-TOKEN", …}data: {status: "ACCEPTED", message: "Content retrieved successfully", contentInfo: {…}, content: "JVBERi0xLjJ6DTEgMCBvYmoNPDwNL0NyZWF0b3IgKFZpc2lvbm…mbyAxIDAgUg0+Pg1zdGFydHhyZWYNMTU2OTg0Mg0lJUVPRg0="}content: "JVBERi0xLjJ6DTEgMCBvYmoNPDwNL0NyZWF0b3IgKFZpc2lvbm"contentInfo: {id: "a2c93187-5422-46c7-bcf7-e663c28dcd2e", externalId: "PVDR-85-625", source: "PCM", fileType: "PDF", rcvdDttm: "2/6/2019 12:00:00 AM", …}message: "Content retrieved successfully"status: "ACCEPTED"__proto__: Objectheaders: {date: "Tue, 11 Jun 2019 18:00:52 GMT", content-encoding: "gzip", x-powered-by: "Express", etag: "W/"200cba-i1BNpy7/54Eg4B7f09qVvKDrg64"", vary: "Accept-Encoding", …}request: XMLHttpRequest {onreadystatechange: ƒ, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}status: 200statusText: "OK"__proto__: Object
DocumentsExpansionPanel.js:133 data.content---> undefined
SearchBoxAction.js:245  downloadDocumentData error---->  DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
    at b64toBlob (http://localhost:3000/static/js/1.chunk.js:32272:26)
    at getData (http://localhost:3000/main.72376b9eb05ec0be6adc.hot-update.js:45:191)
    at http://localhost:3000/static/js/main.chunk.js:2712:9