javascript - URL.createObjectURL(blob);
问题描述
我正在创建 PDF 并在新浏览器中打开。我的问题是单词“blob:”被附加到 URL
斑点:http://localhost:3000/a0b859c9-57a0-40b7-a60f-9d2a72ab3c14
我想成为'http://localhost:3000/a0b859c9-57a0-40b7-a60f-9d2a72ab3c14'
有没有办法我可以做到这一点?我的代码如下
const blob = new Blob([response.data], {type : 'application/pdf'});
var pdfFileUrl = URL.createObjectURL(blob);
window.open(pdfFileUrl);
URL.revokeObjectURL(pdfFileUrl);
update:
I tried below code as well. It also gives the same results.
''
const xhr = new XMLHttpRequest();
//Send the proper header information along with the request
// listen for `onload` event
xhr.onload = () => {
// process response
if (xhr.status == 200) {
// parse JSON data
// console.log( "Response Received")
// var pdfurl = URL.createObjectURL(xhr.response) ;
console.log(xhr.response)
window.open(URL.createObjectURL(xhr.response));
} else {
console.log(" In Error block")
console.error('Error!');
}
};
// create a `GET` request
xhr.open('POST', url);
xhr.responseType = 'blob'
xhr.setRequestHeader('Content-Type', 'application/json');
// send request
xhr.send(JSON.stringify(payload));''
解决方案
推荐阅读
- javascript - How to make an appropriate array for coordinates?
- python - Python - ImportError: cannot import name - another question
- python - VaderSentiment:无法更新表情符号情绪分数
- angular - Error: Uncaught (in promise) - Angular error - NullInjectorError:
- python - Get the second channel from a three channels image as a Numpy array
- vue.js - This relative module was not found: * ../services/Repository, Vue error
- java - empty lines outside of method body with intellij getter/setter templates
- jquery - Push array based on JSON value and key
- sqlite - Order by date in SQLite3
- python - How can I split this list when there's a double new line?