P
P
parkito2017-10-23 18:01:16
JavaScript
parkito, 2017-10-23 18:01:16

How to send file and file status to frontend?

Hello. Prompt, please, best practices for the following purpose.
On the backend, upon request, an object of the form
class CustomFile {
FileStatus status;
byte[] content;
}
On the frontend, after a request to create this file, depending on the status of the file, you need to perform some logic, and then open the byte representation in a pdf reader.
How can this be done with a single request per back? The implementation of the back cannot be changed (on request, it creates a filled CustomFile).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2017-11-16
@firedragon

They say so. Screw on the support check and go.
By the way, and the task is not the registration of the download?
This is possible if the browser supports the download property in anchor elements.
var sampleBytes = new Int8Array(4096);
var saveByteArray = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, name) {
var blob = new Blob(data, {type: "octet/stream"}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = name;
a.click();
window.URL.revokeObjectURL (url);
};
}());
saveByteArray([sampleBytes], 'example.txt');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question