How to create zip files using javascript? - javascript

I found a javascript plugin that could generate zip files, its called jszip.
I tried it, but I think it could only generate the files that will be compiled in a zip file.
What I want is to be able to add existing files to the zip file that it will generate. Is it possible in JavaScript?

Scroll down to the Documentation section on the page you linked to. It describes plainly how to add files to the zip file. For binary files you'll end up using base64, it looks like. For text files you can pass them straight in as strings. Of course you'll need access to the file data in order to add it to the zip file, which is easy enough if you're, say, retrieving said data in an Ajax request, but an uphill battle if you want the user to be able to zip files from his or her local storage.

Related

Save CSV file as a physical file on client machine using Vanilla JavaScript [duplicate]

I have a web application that receives a simple text file, but I need this file to be downloaded to a specific path. Meaning, when the application receives a text file, it will always be downloaded to a specific folder (for example, to C:\MyFolder). If it isn't possible, then I need to copy the file from where user has chosen to my folder.
This application is based on JavaScript.
JavaScript cannot exert any control over my (the visitor's) local filesystem. I remain in complete control of where my downloaded files go, what they are named, and indeed whether I even want to download them in the first place.
Sorry, but the best you can do is inform your users where to put the file you're offering for download. You cannot use JavaScript to choose the destination yourself.
You should be able to do this using a Java applet assuming that you have signed it. The user would be asked to allow your code to run and if allowed, you could do whatever you want: Including downloading a file to a specific location.

Download multiple pdfs to be shipped to user in a single folder - React/firebase?

This is a bit of a process question and not a specific question.
I have an React/Firebase application where the user needs to be able to download multiple pdfs in a single file. The pdfs themselves are not merged together.
Downloading a single pdf from firebase storage isn't too difficult. But how do I collect those pdfs (returned as blobs) into a single folder and then ship that folder to the user as a singular download?
Is there a library for this? Am I thinking about this in the wrong way?
You will likely want a backend firebase function that can retrieve the individual pdfs, and then you can collate them into a single zip object using https://stuk.github.io/jszip/

How to convert DOCX to ODT format using javascript?

I am working on a in-website document editor(word and excel document). So far I am able to edit ODT files using WEBODF. Is there any way to convert DOCX file to ODT using javascript so that i can use the file in the editor? any alternatives for editing word and excel documents inside a website? I have tried saving the file in OneDrive and then using the share link to open editing on sharepoint but this editor cannot be inserted inside an website and can only be done in a new tab? i need the editor inside the website as i need to implement azure versioning of the documents
WebODF is an awesome tool to be used as an online editor. Assuming you have no restrictions implementing a separate backend server, you can use libreoffice, which gives you a command line utility to exactly perform that job. You can convert docx file to odt file using the following command -
soffice --headless --convert-to odt <input file>.docx
The approach would be to create an API
Which would take docx file as input
Store that file temporarily somewhere and run the above command
Serve the converted odt file and delete the temporary files.
If you want to store those files in the server, then you can maintain a database to achieve that as well.
To take care of restricted cross origin policy, you can implement AJAX calls in the front-end to perform file uploading and viewing operations using Javascript blobs.

Download and zip files client side

I'm quite JS newbie and I'm wondering about some idea.
Can javascript be used to download file/multiple files from given url/s on the client side and zip "the stream" on the fly?
I don't want this server side, because I don't want to download files to my server and zip then.
If the following use case is correct:
user selects a bunch of files to zip and the browser zips them up and serves them back to the user.
Then you can use the following library: zip.js
You can check out the demo here
To solve this exact problem, I created a library to stream multiple files directly into a zip on the client-side. The main unique feature is that it has no size limits from memory (everything is streamed) nor zip format (it uses zip64 if the contents are more than 4GB).
Since it doesn't do compression, it is also very performant.
Find "downzip" it on npm or github!

Javascript to save files in browser?

I generate html pages which are viewed locally. Is there a way i can use javascript to save files in a user designated folder? (like C:/dev/myapp/here)
I looked at HTML5 File API on MDN and see how to read files when a user selects them. No way to save files. I know how i can cache files by creating image tags but i like to generate a single button which will kick off a script to download a series of files (zip, gif, png, jpg). I dont suppose i can do that with javascript can i?
I dont suppose i can do that with javascript can i?
Nope, you cannot.

Categories

Resources