Get a bunch of documents using Axios and compress them into a .zip file

I've been struggling to reveal a .zip file in my VueJS application that contains multiple files stored on a remote server. So far, my attempts have only been successful with a single .csv file; the download works fine, but when I try to open the archive, it's considered invalid.

In an effort to solve this issue, I followed the guidance provided in this previous thread:

  try {
    const response = await axios.get(download_url, {
      responseType:'blob'
    });
    
    const url = window.URL.createObjectURL(new Blob([response.data]));
    const link = document.createElement("a");
    link.href = url;
    link.setAttribute("download", "filename.zip");
    document.body.appendChild(link);
    link.click();

  } catch (error) {
    console.log(error);
  }

Although this method allows me to download the .zip file, it's still seen as invalid and cannot be opened. My ultimate goal is to repeat this process with multiple "download_urls" to create a .zip file with multiple files, but for now, I just need to make it work with one file!

Thank you in advance for any assistance you can provide.

Answer №1

  1. Ensure that the link you are using is directly from the axios response (axios.get(url))

  2. If you need to download multiple files in one zip, consider having the server pack them and provide a public link for download (we can provide more details on this if necessary)

  3. Once again, utilize the public link generated by the server to download the zip file

  4. https://i.sstatic.net/XOPZa.png Use the download_url and insert it into a

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Design a circular progress bar with a cut-off at the bottom

Does anyone have suggestions on how to create a circular progress bar with cropping at the bottom, similar to this example: PROGRESS BAR? I've been searching for a component like this but haven't had any luck. Any ideas, especially utilizing Mate ...

Extract all links from an external website

I'm attempting to extract all the URLs from a webpage using jQuery so that I can later use them with $.get(). If these URLs were located on the same page as the script, retrieving them would be easy by doing something like var links = document.getEle ...

Overlap one element entirely with another

Currently, I am working on a way for an element called overlayElement to completely cover another element known as originalElement. The overlayElement is an iFrame, but that detail may not be significant in this scenario. My goal is to ensure that the over ...

When the mouse hovers over the slider, the final image jumps into view

After successfully building an image slider that displays 2 partial images and 1 full image on hover, I encountered a bug when setting the last image to its full width by default. This caused a temporary gap in the slider as the other images were hovered o ...

Executing code within Vue js $set method's callback

For my v-for loop that generates a list of flights, I have implemented functionality where the user can click on a "flight details" button to send an AJAX request to the server and append new information to the results array. To update the view accordingly ...

I am facing an issue with properly linking my jQuery

After searching through numerous posts on this website, I have yet to find a solution to my problem. My issue involves trying to implement a simple jQuery function that is not functioning as expected. It appears that the jQuery link may not be properly set ...

What are the steps to ensure that this iframe adjusts perfectly to the page in terms of both vertical and horizontal dimensions

I have a sandbox from Material UI that you can view at this link: https://codesandbox.io/s/material-demo-forked-c8e39?file=/demo.js Upon loading the page, an iframe displays some HTML content. Although the width fits perfectly, there are two vertical scro ...

Access model information from a controller with the help of Next.js and Sequelize

I'm currently working on a project involving Vue.js as my frontend and Next.js as my backend. While everything seems to be running smoothly, I am facing an issue with retrieving my model data back to my controller... Additional details: I have utili ...

I created a custom function that combines two arrays into one, but I am encountering an error stating "Unable to access properties of undefined."

I am facing a challenge with combining two arrays into one new array that merges the objects of each array together. While I know how to merge two arrays into a single array, I am struggling to combine the actual objects into a brand new object within that ...

Image encoded in base64 not appearing on the screen

Hey there, I'm currently working on implementing a jQuery image uploader that generates a base64 code when an image is selected. function readImage(input) { if (input.files && input.files[0]) { var FR= new FileReader(); FR.onload ...

Jquery-ajax fails to accomplish its task

I am just starting to learn about ajax and recently created a simple page on my local server to practice sending and receiving data from/to a JSON file in the same directory. Although the GET method is working perfectly fine, I am having trouble understan ...

Issue with loading controllers in route files [Node.js]

I've encountered an issue while trying to include a user controller into my routes for a node js app. Everything was working fine until suddenly it started throwing an error message. I've thoroughly checked the code for any potential issues but s ...

What is the best way to streamline these two JavaScript lines and eliminate redundancy?

In order to address an issue, I implemented the following two lines of code: MyString = div.getAttribute('data-type') || div.getAttribute('data-id'); MyString = MyString.replace('RemoveThis', ''); Although the code ...

Next.js is causing an error by not recognizing the document variable

While diving into the world of next.js, I encountered an interesting challenge. In my project, I came across this puzzling error. The culprit seemed to be a module called Typed.js, which threw me off with a peculiar message: Server Error ReferenceError: d ...

Unable to perform a POST request and send JSON data using AJAX with jQuery at the

It seems like there may be a server issue causing this problem, and unfortunately, I don't have access to our server to troubleshoot. I was hoping that someone else might have a solution or could help me understand the root cause of the issue. The is ...

Error: In Nodejs Promises, you cannot invoke the "then" method on an undefined value

Could you clarify what's incorrect about the following code snippet? var promise = fs.readFile(file); var promise2 = promise.then(function(data){ var base64 = new Buffer(data, 'binary').toString('base64'); res.e ...

Tips for establishing a connection between a Node.js application and PostgresSQL hosted on Heroku

I have utilized Vue, webpack, Express and PostgresSQL in the development of my app. After deploying my app to Heroku, I established a PostgresSQL database on the platform. In the image below, you can find the Database Credentials: https://i.sstatic.net/aI2 ...

loading a module's dependencies seamlessly with RequireJS

Currently, I am working with Knockout and Require in my project. I have isolated some Knockout handlers into a separate module that I want to utilize. While there is no specific JavaScript code relying on this module, it is referenced in the data-bind attr ...

Struggling to send Python JSON object using Django AJAX

Having some trouble implementing the ajax plugin for Django from https://github.com/yceruto/django-ajax. I've managed to use ajaxPost successfully, but I'm facing issues with ajaxGet. Within views.py, all the data is being printed correctly in P ...

jQuery ceases to function once AJAX content is loaded

Exploring Options for Flexible Data Display I'm currently in the process of building a webpage that allows users to choose between different layouts for loading data. This includes the option to display data in either a list format or a card interfac ...