Last active
March 7, 2018 17:39
-
-
Save 11joselu/2096717e444849b597a5a2e3f2080eaf to your computer and use it in GitHub Desktop.
Donwload File - Vue.js 2.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getFile(response) { | |
var result = document.createElement('a'); | |
var contentDisposition = response.headers.get('Content-Disposition') || ''; | |
var filename = contentDisposition.split('filename=')[1]; | |
filename = filename.replace(/"/g,"") | |
return response.blob() | |
.then(function(data) { | |
result.href = window.URL.createObjectURL(data); | |
result.target = '_self'; | |
result.download = filename; | |
return result; | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fileUtil from '../fileUtils'; | |
this.$http.post('/generate', data) | |
.then(fileUtil.getZIPData) | |
.then((link) => { | |
link.click(); | |
}) | |
.catch((err) => { | |
console.log(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@11joselu I do not understand what needs to be the result from your api call? The file path?
And why do you use getZIPData when getZIPData is not mentioned in fileUtils.js?