我正在运行gotenberg作为我的文档到PDF转换API,它正在与cURL一起工作。
cURL命令如下所示
curl --request POST --url http://example.com --header 'Content-Type: multipart/form-data' --form files=@file.docx > result.pdfAPI只适用于cURL,当我尝试用Postman或AJAX点击相同的API时,我会得到一个响应,但是在保存详细信息或使用Postman预览响应时,我会得到一个空的PDF文件。
我的AJAX请求如下所示
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}有人能说明一下我的要求是怎么回事吗?
我通过响应获得以下标题,但是所创建的文件为空

发布于 2018-11-23 08:13:42
我需要处理blob响应,因此我的AJAX调用必须如下所示。
var settings = {
"async": true,
"crossDomain": true,
"url": "http://convertionapi.com",
"method": "POST",
"processData": false,
"contentType": false,
"data": form,
"xhr": function(){
var xhr = new XMLHttpRequest();
xhr.responseType= 'blob'
return xhr;
},
success: function(data){
console.log("Success", data);
s3.upload({
Key: "files/test.pdf",
Body: data,
ContentType: 'application/pdf',
ACL: 'public-read',
},function(err, data) {...}
},
error: function(err) {
console.log("Error", err);
}
}https://stackoverflow.com/questions/53427103
复制相似问题