Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change name of download in javascript

If a user clicks on a downloadable link such as

<a href="downloadable.txt">Download</a> 

Is there a client-side (html or javascript) way to change the name of the file before the 'Save As' dialog?

like image 368
Intra Avatar asked Apr 06 '12 20:04

Intra


People also ask

How to rename file name in JavaScript?

To rename a file we have to create a new file and pass our new name to the File constructor. const myRenamedFile = new File([myFile], 'my-file-final-1-really. txt'); console.

How do I change the name of a file downloaded from my browser?

Click on the "Edit Menu" > Preferences > General tab. Locate the "Save downloaded files to" section, Click on "Downloads" > "Other"... Browse and indicate your new download location.

How to change image file name in JavaScript?

slice(0, file. size, 'image/png'); newFile = new File([blob], 'name. png', {type: 'image/png'});


1 Answers

HTML5 provides the a[download] attribute which lets you rename a file. This example will download link.txt and rename it something.txt.

​<a download="something.txt" href="link.txt">asdf</a>​​​​​​​​​​​​​​​​​​​​​​​​​​​ 

Note that this only works on same-origin URLs (i.e. not across different domains).

like image 145
Dennis Avatar answered Oct 08 '22 00:10

Dennis