File downloading using client-side javascript

Related tags

Files download
Overview

download

NPM version Size License CDNJS

Summary


The download() function is used to trigger a file download from JavaScript.

It specifies the contents and name of a new file placed in the browser's download directory. The input can be a URL, String, Blob, or Typed Array of data, or via a dataURL representing the file's data as base64 or url-encoded string. No matter the input format, download() saves a file using the specified file name and mime information in the same manner as a server using a Content-Disposition HTTP header.

Getting and Using


Via NPM/Bower

npm install downloadjs
bower install downloadjs

require("downloadjs")(data, strFileName, strMimeType);

Simple global download function via

Comments
  • Support download of MS Office docx and xlsx files

    Support download of MS Office docx and xlsx files

    Thank you for this great resource. I'm using it to download files returned from a request that uses a proxy and the link to the documents cannot simply be placed in an <a href>

    I can successfully download all file types with the exception of the microsoft office docx and xlsx types. When attempting to open the downloaded files with MS Office I get an error message stating that they are corrupt and cannot be repaired.

    I have tried including the correct mime type application/vnd.openxmlformats-officedocument.wordprocessingml.document

    AND

    leaving the mime type blank (anddefaulting to application/octet-stream)

    Both result in corrupted file.

    Any ideas how to support the download of those file types correctly?

    my code:

    var x = new XMLHttpRequest();
     x.open("GET", attachUrl, true);
     x.responseType = 'blob';
    // with correct mime type
    //x.onload = function (e) { download(x.response, name, file.ContentType); }
    // without mime type
    x.onload = function (e) { download(x.response, name); }
    console.log(file.ContentType);
    x.send();
    

    and the error message in MS Office corrupt

    opened by brightrain 9
  • URL characters replaced by Dashes

    URL characters replaced by Dashes

    Hi, When using download.js, some characters became dashes. http:// became http--- for exemple.

    tested codepen with debug mod.

    Thanks for your support !

    opened by X-Raym 8
  • Safari 9

    Safari 9

    This does not seem to work on safari 9+

    http://pagedemos.com/sxks39b72aqb/1 http://pagedemos.com/sxks39b72aqb/2

    generate nothing

    http://pagedemos.com/sxks39b72aqb/3

    Failed to load resource: Frame load interrupted

    opened by iamjonbradley 6
  • Downloadjs breaks PDF file

    Downloadjs breaks PDF file

    The library breaks PDF file and produces invalid PDF which opens with blank pages. PDF Example: http://partners.adobe.com/public/developer/en/xml/AdobeXMLFormsSamples.pdf

    Code:

    $.ajax({
            url: '/AdobeXMLFormsSamples.pdf',
            success: download.bind(true, "application/pdf", 'AdobeXMLFormsSamples.pdf'), 
            complete: function(){...}
        });
    

    Tested on browsers:

    • Chromium Linux Version 44.0.2403.61 (64-bit)
    • Firefox Linux 38.0.5
    opened by ashl1 6
  • docx, ods

    docx, ods

    Hi, in my app i was using just this piece of js:

    var link = document.createElement("a"); link.download = dataItem.Filename; link.href = data; link.click();

    where data is the data uri with mime type etc... this is working perfectly on chrome, but not in ie so i used your library, and it's perfect for ie the only issue is that is not working with documents like docx, ods...

    opened by deatk 5
  • download file from URL

    download file from URL

    Hi,

    maybe it's a simple question, but I can't make it myself:

    how has the function to look alike if I want to download an existing file?

    like the filename is "image.jpg"?

    thank you!

    opened by mgk89 5
  • html5 A[download] trick is leaking click events

    html5 A[download] trick is leaking click events

    In the saver() function where an invisible anchor element is used to start the download, clicks are allowed to bubble up to the document root.

    https://github.com/rndme/download/blob/31cf0fa096b2171c569e694e2416df2182449d01/download.js#L111

    It would be great if the call to anchor.click() would stop clicks from propagating to the body element.

    opened by sliekens 4
  • Chrome breaks if base64 url is bigger than 2MB

    Chrome breaks if base64 url is bigger than 2MB

    This is quite an old bug but it looks like it has not been resolved yet. Basically when I try to use your plugin to download a base64 that is bigger than several MB (from a canvas), I get "network error" instead of the proper file. Probably you should switch to Blob if the base64 string is too long.

    opened by albertogasparin 4
  • Error downloading PDF from IE: InvalidCharacterError

    Error downloading PDF from IE: InvalidCharacterError

    Using base64 encoded content, I can download text and images. I can also download PDFs in chrome.

    However, I'm getting an error when downloading the same PDF in Internet Explorer 11.

    index.txt

    How can I fix this?

    opened by yamizukin 3
  • Safari 7.1 download

    Safari 7.1 download

    I've tried setting up a simple string download which works fine in Chrome and Firefox but not in Safari 7.1. After triggering the download I can see the data being inserted into the current page real quick and then it disappears.

    download('This is some string', filename, 'text/plain');

    opened by alocher 3
  • error: download is not a function

    error: download is not a function

    I don't know how to describe it properly, and neither do I have a MRE. But it seems that if the main function is called "download", that creates an error as described in the title.

    I have renamed your function to something else (e.g. "downloadit") and then it worked.

    No idea what might be triggering this error (I am using OS X version 10.9.5 and Chrome Version 64.0.3282.167), but I hope this might be of help somehow.

    opened by dusadrian 2
  • anyone had problems using many chrome parallel downloads?

    anyone had problems using many chrome parallel downloads?

    I'm using this library to download files from our API. But now i see that if I start more than 80 requests instantly and then I download them using this lib, some files are not downloaded (no errors seen in console or in requests). Requests seems to be there with status: 200, but there are missing files in my downloads folder. This works ok in FF. Anyone had this issue? I've managed to improve this by not starting all requests when user press 'download' all, I've created a Queue and when some requests are done, i'm starting others.

    opened by nmatei 1
  • Unable to generate .xlsx file from the data

    Unable to generate .xlsx file from the data

    Hi,

    Thanks you very much for this great resource. I am using this to download Excel file with extension .xls by passing the html data as a data variable and no issues found it works perfectly as expected. But now I need to download the same Excel file with extension .xlsx and I have tried calling download function as per below code snippets:

    download(data, "text.xslx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

    And also: download(data, "text.xslx", "text/xlsx")

    It always gives me below error when I open the downloaded file: image

    I read all the relevant articles but could not find the solution. There was an article/issue which was fixed(https://github.com/rndme/download/issues/21) but that was related to the download .xlsx file from the URL and I need to download from the data which I am passing. This passing data contains the dynamically generated html file.

    Could you please help me in resolving this issue or guide me what mistake I am making ?

    Thanks in advance ! Ajay

    opened by ajaywcc9032 0
  • Type declarations

    Type declarations

    Hello Dan!

    I'm using your "download" library quite often - thank you very much for this work!

    But since I'm mostly developing in TypeScript now, I thought it might be a good idea to provide a type declaration file for it.

    And, well, since I'm also developing with Svelte, I just added an export declaration for package.json as well.

    Perhaps, you'll find it useful.

    With greetings from Germany,

    Andreas Rozek

    opened by rozek 0
  • Chrome don't support download attribute in anchor tag

    Chrome don't support download attribute in anchor tag

    Chrome don't support download attribute in anchor tag when yo click this link chrome force to download file and in my case need that open file and don't work if remove download attribute work fine.

    function saver(url, winMode) { if ('download' in anchor) { //html5 A[download] anchor.href = url; anchor.setAttribute("download", fileName); //THIS LINE anchor.className = "download-js-link"; anchor.innerHTML = "downloading..."; anchor.style.display = "none"; document.body.appendChild(anchor); setTimeout(function () { anchor.click(); document.body.removeChild(anchor); if (winMode === true) {setTimeout(function () { self.URL.revokeObjectURL(anchor.href);}, 250);} }, 66); return true; }

    opened by lazaro770407 1
Releases(v1.4.7)
Owner
dandavis
javascript developer
dandavis
Client/server side PDF printing in pure JavaScript

pdfmake PDF document generation library for server-side and client-side in pure JavaScript. Check out the playground and examples. This is unstable ma

Bartek Pampuch 10.5k Jan 1, 2023
Blaze is a file sharing progressive web app built using WebTorrent and WebSockets

Blaze is a file sharing progressive web app(PWA) that allows users to transfer files between multiple devices. I

Akash Hamirwasia 1.6k Jan 4, 2023
A command line interface for file handling using JCore.FileSystem

JCore.FileSystem.Cli Table of Contents JCore.FileSystem.Cli Table of Contents Introduction Installation Uninstall Usage References Articles Packages T

Sniper Code 1 Jan 21, 2022
MyDrive is an Open Source cloud file storage server (Similar To Google Drive)

MyDrive is an Open Source cloud file storage server (Similar To Google Drive). Host myDrive on your own server or trusted platform and then access myDrive through your web browser. MyDrive uses mongoDB to store file/folder metadata, and supports multiple databases to store the file chunks, such as Amazon S3, the Filesystem, or just MongoDB. MyDrive is built using Node.js, and Typescript. The service now even supports Docker images!

null 2.8k Dec 30, 2022
JCore.FileSystem - File system API based on Node.js

JCore.FileSystem Table of Contents JCore.FileSystem Table of Contents Introduction Installation Uninstall Exposed API Network File Release Package Int

Sniper Code 1 Jan 21, 2022
Pretty diff to html javascript library (diff2html)

diff2html diff2html generates pretty HTML diffs from git diff or unified diff output. Table of Contents Features Online Example Distributions Usage Di

Rodrigo Fernandes 2.3k Dec 31, 2022
PDF Reader in JavaScript

PDF.js PDF.js is a Portable Document Format (PDF) viewer that is built with HTML5. PDF.js is community-driven and supported by Mozilla. Our goal is to

Mozilla 41.1k Jan 8, 2023
A JavaScript PDF generation library for Node and the browser

PDFKit A JavaScript PDF generation library for Node and the browser. Description PDFKit is a PDF document generation library for Node and the browser

null 8.5k Jan 7, 2023
Moxiecode 5.6k Jan 1, 2023
A simple Node.js APIBAN client for downloading banned IPs and inserting them into a redis set

apiban-redis A simple Node.js APIBAN client for downloading banned IPs and inserting them into a redis set. Installation This utility can be run as a

jambonz 4 Apr 5, 2022
Fast and minimal JS server-side writer and client-side manager.

unihead Fast and minimal JS <head> server-side writer and client-side manager. Nearly every SSR framework out there relies on server-side components t

Jonas Galvez 24 Sep 4, 2022
Easy server-side and client-side validation for FormData, URLSearchParams and JSON data in your Fresh app 🍋

Fresh Validation ??     Easily validate FormData, URLSearchParams and JSON data in your Fresh app server-side or client-side! Validation Fresh Validat

Steven Yung 20 Dec 23, 2022
A Javascript library to export svg charts from the DOM and download them as an SVG file, PDF, or raster image (JPEG, PNG) format. Can be done all in client-side.

svg-exportJS An easy-to-use client-side Javascript library to export SVG graphics from web pages and download them as an SVG file, PDF, or raster imag

null 23 Oct 5, 2022
Restream is a module that allows you to create a stream of an audio/video file from the Firebase storage, protected from direct download through the client-side.

nuxt-restream Restream is a module that allows you to create a stream of an audio/video file from the Firebase storage, protected from direct download

Restorm 3 Dec 13, 2022
Multithread emulator. The wrun allows you to dynamically run a function inside a Web Worker on the client side, without the needing of a dedicated file

wrun This lib allows you to dynamically run a function inside a Web Worker on the client side, without the needing of a dedicated file. This means tha

Felippe Regazio 9 Nov 5, 2022
Wallpik is a stock images & wallpapers downloading web app built with vanilla JavaScript & Pexels API

Wallpik the stock photos & wallpaper web app (Preview) Wallpik Wallpik is a single page application built with HTML, CSS, Vanilla JavaScript & Pexels

Shivaraj Padala 4 Apr 19, 2022
A javascript based whatsapp bot for downloading and sending media from youtube and facebook in different formats alongwith couple of other features.

Whatsmazan Available Features Downlaod youtube mp4 Video and send Downlaod youtube mp3 audio and send Search something from youtube Downlaod facebook

mazan labeeb 10 Oct 30, 2022
Make drag-and-drop easier using DropPoint. Drag content without having to open side-by-side windows

Make drag-and-drop easier using DropPoint! DropPoint helps you drag content without having to open side-by-side windows Works on Windows, Linux and Ma

Sudev Suresh Sreedevi 391 Dec 29, 2022
This Plugin is For Logseq. If you're using wide monitors, you can place journals, linked references, and journal queries side by side.

Logseq Column-Layout Plugin Journals, linked references, and journal queries can be placed side by side if the minimum screen width is "1850px" or mor

YU 14 Dec 14, 2022