download image in vuejs

   downloadImage(path) {

                var filename = path.replace("storage/images/","")
               var query = this.getAuthHeaders();
                query["params"] = {};
                query["params"] = {
                    path: path.replace("storage/","/app/public/"),
                    filename: filename
                };
                query["responseType"] = 'blob';
                this.axios
                .get(this.getApiUrlByProcess('media-analysis','get_download'), query)
                .then(response => {
                    const url = window.URL.createObjectURL(new Blob([response.data]));
                    const link = document.createElement('a');
                    link.href = url;
                    link.setAttribute('download', filename);
                    document.body.appendChild(link);
                    link.click();
                })
                .catch(err => {
                    console.error(err);
                });
            },

No comments:

Post a Comment

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...