I've uploaded a PDF file (Size 30MB) on a File type Field.
I'm then trying to display the PDF from the field on a web resource but it doesnt show. If I try to display the same PDF from annotation entity, it displays fine. This is how I'm fetching the data from file type field:
var startBytes = 0;
var req;
var increment = 4194304;
var clientUrl = Xrm.Utility.getGlobalContext().getClientUrl();
var url = clientUrl + "/api/data/v9.1/my_entity(" + recId + ")/my_fields?size=full";
while (startBytes <= fileSize) {
var result = await makeRequest("GET", url, startBytes, increment);
req = result.target;
if (req.status === 206) {
finalContent += JSON.parse(req.responseText).value;
startBytes += increment;
if (fileSize === 0) {
fileSize = req.getResponseHeader("x-ms-file-size");
fileName = req.getResponseHeader("x-ms-file-name");
}
}
else if (req.status === 404) {
break;
}
}
if (fileBodyAndMimeType[1] === "pdf") {
var newSrc = "data:application/pdf;base64," + finalContent;
const blob = dataURItoBlob(newSrc);
var temp_url = window.URL.createObjectURL(blob);
$("#myframe").attr("data", temp_url);
document.getElementById("myImage").style.display = "none";
}
The above dataURItoBlob methog gives me the following error:
DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
How to display the PDF from file type field on a web resource correctly?