Jack Cawthra
Jack Cawthra

Reputation: 7

JavaScript changing default file name?

How would I go about changing the name of a clip that is going to be downloaded by the client on a website? Each video clip currently downloaded is a default name how do I go about customising it?

Upvotes: 0

Views: 304

Answers (1)

Sumit Kumar
Sumit Kumar

Reputation: 404

Yes, you can change file name as per your own logic. and will be download in client browser as per following logic :

var blob = b64toBlob(b64Data, contentType, false);
var blobUrl = URL.createObjectURL(blob);
var a = document.createElement("a");
document.body.appendChild(a);
a.style.display = 'none'
a.href = blobUrl;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(blobUrl);

FileName can be set as per your own logic and append file extension

b64Data = your file's binary data, contentType = content type of your file. for example for image it will be "data:image/png;base64,"

Upvotes: 1

Related Questions