如何解决使用 XmlHttpRequest 将 PDF 文件发送到 API
我在向 api 发送 pdf 文件时卡住了,控制台中没有显示错误,但响应是
<script>
function myFunction() {
const selectedFile = document.getElementById('file');
console.log("fileInput",file)
console.log("hERE I AM",selectedFile.files[0]);
console.log("hERE I AM",selectedFile.files[0].name);
var data = new FormData();
let blob = new Blob([selectedFile.files[0]],{type: 'application/pdf'});
data.append("file",blob,selectedFile.files[0].name);
data.append("request","{\n \"signers\": [{\n \"identifier\": \"aparna.bhargav@capitalvia.com\",\n \"name\": \"Aparna Bhargav\",\n \"reason\": \"Loan Agreement\"\n }],\n \"expire_in_days\": 10,\n \"display_on_page\": \"all\",\n \"notify_signers\": true\n}\n");
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange",function() {
if(this.readyState === 4) {
console.log("inside 4",this.responseText);
}
if(this.readyState === 1) {
console.log("inside 1",this.responseText);
}
if(this.readyState === 2) {
console.log("inside 2",this.responseText);
}
if(this.readyState === 3) {
console.log("inside 3",this.responseText);
}
});
xhr.open("POST","https://cors-anywhere.herokuapp.com/https://api.digio.in/v2/client/document/upload");
xhr.setRequestHeader("authorization","Basic QUlUMU1ZNFk0RjU4R1FZNVRPM09RU1NBUElIS1hMU086UTVUNExCTUFYUDNTRkNRVkM1NFNDR0dRSkZCRjNXVzE=");
xhr.setRequestHeader("content-type","multipart/form-data");
// xhr.setRequestHeader("Access-Control-Allow-Origin","https://api.digio.in/v2/client/document/upload");
xhr.send(data);
var inputVal = document.getElementById("email").value;
console.log("hello print",inputVal)
}
</script>
请提出实现相同目标的最佳方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。