Answer the question
In order to leave comments, you need to log in
Why is the zip file corrupted after downloading?
I'm trying to give the user a zip file for downloading. Front - vue.js, back - django rest.
So I wrap a zip file on the back:
return FileResponse(open('static/Letters.zip', 'rb'), content_type='application/zip')
axios.post('http://127.0.0.1:8000/api/create_letter_to_the_debtor', JSON.stringify(body))
.then(
function (response) {
let blob = new Blob([response.data],)
let link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = 'Letters.zip'
link.click()})
.catch(e => {
console.log(e.response)
});
Answer the question
In order to leave comments, you need to log in
solved the problem, peeped Here , you need to change:
axios.post('http://127.0.0.1:8000/api/create_letter_to_the_debtor', JSON.stringify(body))
.then(
function (response) {
let blob = new Blob([response.data],)
let link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = 'Letters.zip'
link.click()})
.catch(e => {
console.log(e.response)
});
axios({
method: 'POST',
url:'http://127.0.0.1:8000/api/create_letter_to_the_debtor',
data: JSON.stringify(body),
responseType: 'blob',
})
.then( (response) => {
// response => console.log(response))
console.log(response)
let blob = new Blob([response.data], { type: 'application/zip' })
let link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
document.body.appendChild(link);
link.click()
document.body.removeChild(link);
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question