Reputation: 991
There is a PDF in a BLOB field of a table in the 4Dv15 database that Wakanda is connected to. When I pull the BLOB from the field in a serverside script (in Wakanda), it is an object:
{'size': 12915, 'type': 'application/octet-stream'}
The PDF or binary data do not appear to be in the returned object. I want to deliver the PDF inside the BLOB to the client. Can you help me figure out how to do this?
Thank you
Edit: This is what I get when I try using the code:
console.log(blob);
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
Edit 2: This is the serverside code I am using to get the blob. I am just trying to get it to work here. There is only one record in the table and it has a PDF in the BLOB.
var reportCollection = ds.ReportLog.all();
var blob = reportCollection[0].ReportBlob;
The result of this code is the object seen above-- I see no evidence that 4D is returning the binary data of the BLOB but instead only the properties of that BLOB.
Upvotes: 0
Views: 184
Reputation: 3541
From a Wakanda Request Handler you could use sendChunkedData()
:
response.sendChunkedData(blob)
Or write the blob to a file on the server using .copyTo()
from the BLOB API and serve the file to the client:
var myFile = new File (outputFolder + filename)
blob.copyTo(myFile)
Another option may be the URL.createObjectURL static method which could be used like this:
var objectUrl = window.URL.createObjectURL(blob)
window.open(objectUrl)
See also: URL.revokeObjectURL
Upvotes: 1