I want to download file from external server but after renaming it. Let's say http://playtictactoe.atwebpages.com/logo.png is an image file I want to download. I have used the following HTML:
<a href="http://playtictactoe.atwebpages.com/logo.png" download="myName.png">
Download File
</a>
But this doesn't rename the file. I've read somewhere that this is because of Response Header on server. Is there any way to ignore Response Header on client side? Else guide me any other solution.
You can download the file as a buffer and resave with the file api like descriped here:
HTML5 File API downloading file from server and saving it in sandbox
Or lookup FileAPI and XMLRequest to Buffer. You download the file as binaryBuffer save it with fileAPI and rename it. This should also work in Firefox. But this is not the simple solution you are searching for. Even though it works ;-)
You can then rename the file like you want.
Cheers
Related
I have a .desktop file and I want to read the icon png image file path in javascript so I can display it in my html file. How would I go about doing this?
This is what my .desktop file looks like:
[Desktop Entry]
Version=1.0
Name=BackMeUp
Comment=Back up your data with one click
Exec=/home/alex/Documents/backup.sh
Icon=/home/alex/Pictures/backup.png
Terminal=false
Type=Application
Categories=Utility;Application;
Any help would be greatly appreciated!
If the javascript you saying is only the javascript in browser, it's impossible except you upload the file to a server and analyze it.
1.browser javascript and server
First of all you should have a form that you can upload your .desktop file, and then you upload to a server(you can use node.js to build a server).
After the server received it, you can read its content as text and find the line of Icon and then response to browser
2. serverside javascript: node.js
if you can use node.js for reading this file, it's much easier.
just install node.js and build a .js file and use fs.readFileSync to read the .desktop file and analyze it line by line.
I am creating browser based video editing tool. I want a user to first download a ~70mb javascript file and store it somewhere on his computer. I want to link that file when my website is opened. How can I achieve that.
EDIT
What i meant is that there are various files like js1.js,js2.js... all sums upto 70mb . So i will offer a zip folder to download and only link js1 or js2 file etc depending on the effects user wish to apply
i am sorry to inform you but i think there is something really wrong with what you are trying to do.
A "solution" would be to just cache the javascript on the user's browser so any subsequent requests parse the cache instead of requesting the resource again from the server.
You should know however that if you are in need to download ~70mb of a javascript file you are doing something wrong. I have a whole web app project that when published the total size is around 60mb, all files required to properly run included, and its a damn big codebase in there.
I find it very hard to believe there is ever a need for a single javascript file to be that big, in any case maybe a simple caching should do the trick
That is actually done automatically. Once you add a <script> tag with a link to a local js file (also stored on the server) the file is loaded automatically.
See HTML <script> src Attribute for more information on that.
You can only reference to js files on the server. Files on the server could look like this:
index.html
somefancyjsfile.js
You can then reference from inside your html file to the js file via the <script> tag.
I'm not sure though if the size is not a bit too much...
I want to initiate a file download from react, such that the browser downloads it as any regular file.
When I use fetch, I can download the file and do what I want, but is not downloaded with the browsers download manager. The files are rather large, that is why I want the browser to manage the download.
I asked you if you have the full URL to the file.
If you want to start the download from a link, use the solution Kielstra provided. If you want to start the download using javascript, use the following code:
window.location = url_to_file;
If you have the URL to the file that you want to be downloaded, you can simply create a link to it with the download attribute.
<a href="link_to_file" download>Download</a>
Is it possible to create and save a PDF file from dataUri-string with jsPDF?
This is my saved string in the database:
var pdfAsDataUri = "data:application/pdf;base64,JVBERi0xLjUK...";
Thanks
The HTML5 download attribute allows you to specify the desidered filename.
This works only in some browsers.
http://caniuse.com/download
So instead of using
window.open("data:application/pdf;base64,JVBERi0xLjUK...");
you can create a download link:
download
To create your download link in javascript using the download attribute and downloading it directly:
var a=document.createElement('a');
a.download='FileName.pdf';
a.href=pdfAsDataUri;
a.click();
else, like i said
window.open(pdfAsDataUri);
but no filename can be specified.
Another solution is to use php and output the correct headers, a binary file and the filename.
As it's not clear which db you are using and where do you want to save the file,
btw, if i maybe didn't understand your question correctly and you want to store the pdf somewhere on the server than you need in any case some serverside programming language like php, asp, nodejs and many more.
i am using PDFJS to render PDFs files using their URL after scanning the current page a js snipet return the urls. then it passes them to pdfJS. until now everything works the problem show when the PDF is already open in the browser . i take the URL (*.pdf) and pass it the same way as before the difference is that the file is not downloaded and i have this response.
Warning: Unhandled rejection: Unexpected server response (0) while retrieving PDF "http://geekographie.maieul.net/IMG/pdf/progit.fr.pdf".
(just for the record i dont have CORS issues).
Try this "http://mozilla.github.io/pdf.js/"
Installation
download and unzip file.
put "PDF" file in this folder.
config in "viwer.js", edit var DEFAULT_URL.
upload folder to server.
Have fun!