G
G
GrimJack2017-06-09 13:40:21
JavaScript
GrimJack, 2017-06-09 13:40:21

How to set the filename when rendering it from a stream?

The server (in Laravel) generates a PDF and sends it as a string to the client in Angular.
The client outputs this way:

spoiler
var file = new Blob([response.data], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
$window.open($sce.trustAsResourceUrl(fileURL));


Now the client wanted to assign names to documents. How can this be done for a blob?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2017-06-09
@Stalker_RED

Try like this

var blob = new Blob([response.data], {type : 'application/pdf'});
var fileOfBlob = new File([blob], 'fileName.pdf');
...

N
Negwereth, 2017-06-09
@Negwereth

If you need to give the name from the server, then try it in the response header.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question