The page after the jump can be displayed, and the links generated by the blog are returned, but the preview is blank, and the console warns: warning: invalid stream: “formaterror: bad fcheck in flat stream: 120, 239”
Follow the source code to see the reason for the warning. There should still be a problem.
Solution:
When Axios requests the document flow, the responsetype is changed to blob
If the responsetype is not modified, JSON is the default in Axios.
If it is set to null in XHR, the default is text, and the link: https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/responseType
// originally written here is this.$axios.get(`/api/preview?id=${id}`)
// later found the problem here, $axios is encapsulated axios, did not set the requestType, and I only cross-referenced the returned data is the document stream after ignoring the problem!
// $request is the axios directly thrown out
this.$request({
methods: 'GET',
url: `/api/preview?id=${id}`,
responseType: 'blob'
})
.then(res => {
console.log(res)
var blob = new Blob([res.data], {
type: 'application/pdf;chartset=UTF-8'
})
const fileURL = URL.createObjectURL(blob)
window.open(`${path}pdf/web/viewer.html?file=${fileURL}`)
})
.catch(err => {
console.log(err)
})
Read More:
- PDF.js load PDF Error: Message: failed to fetch
- [Solved] IE Browser Error: unhandled promise rejection error: access is denied. File stream Download
- [Solved] PDF.js Error: Cannot use the same canvas during multiple render()
- [Solved] Vue3 npm ERR code ERR_SSL_DECRYPTION_FAILED_OR_BAD_RECORD_MAC
- Interface request error 504 gateway time out [How to Solve]
- Error in created hook: “SyntaxError: Unexpected token u in JSON at position 0
- Trigger http request when tab page is closed in angular2+ project
- How to Solve Uncaught (in promise) Error (Two Solutions)
- Using for in loop complex data types (object and array) in ES6
- How to solve Uncaught (in promise) error in VUE?
- The date selector Report Null Error in element is cleared
- [Solved] AES encryption in ie11 results in an error (missing ‘)‘
- Difference between contenttype and datatype in Ajax request of jquery
- uniapp [Vue warn]: Error in onLoad hook: “TypeError: Attempting to change the setter of an unconfigu
- [Solved] Echarts Error: Uncaught (in promise) Error: Initialize failed: invalid dom.
- [Solved] Vue2 Cross-domain Error: AxiosError net::ERR_FAILED, Network Error, ERR_NETWORK
- [Solved] Vue3 Error: Cannot use ‘in‘ operator to search for ‘path‘ in undefined
- [Solved] Error in created hook: “SyntaxError: Unexpected token o in JSON at position 1“
- Solve the asynchronous execution of callback function in Axios request processing interceptor
- Vue Error: error in mounted hook: TypeError: invalid src type