I am doing a Domino-REST server call to create a PDF. The server creates the PDF and send the PDF as byte[] to the client. Now I want to download the byte[] to the client computer without opening another browser window.
I'll found this question: File download a byte array as a file in javascript / Extjs which describes the way, how to do that.
Now, I am facing the problem, that I have to convert my byte[] to a Blob using elemntal2.
Any help is appreciated. Thanks
First, let's take a quick look at the MDN docs for Blob's constructor arguments:
This gets us far enough to understand this code in the linked answer:
which is first creating a typed array of unsigned int8s, then wrapping that UInt8Array in an array and using it to construct a Blob with the specified MIME type.
In elemental2, we have these same constructors - but I think we're going to want to use a different TypedArray type here, since Java
bytes are signed, so instead let's look atelemental2.core.Int8Array(also available at MDN for clearer documentation). We can either use a constructor to create anInt8Array, or can use the staticfrom(...)method. Neither of these actually accept abyte[], but either want adouble[]orJsArrayLike<Double>- from our perspective as Java developers, these seem wrong, but from JS's perspective a GWTbyte[]is usually just a plain JS array that just happens to have smallNumbers in it (which map to JavadoubleorDouble.So we cheat, and cast to what we actually want. The rest of the code just deals with making arrays of union types, a corner case of Elemental2 and JsInterop that we usually don't have to look closely at.