文档信息提取-SAPUI5 Ajax POST调用

2020-08-14 10:33发布

点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)我正在尝试将pdf发布到 doc...

         点击此处--->   EasySAP.com群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)


我正在尝试将pdf发布到" document-information-extraction/v1/document/jobs"中以进行处理并提取文本。 邮寄电话就是这样-

var data1 = new FormData();

this.onuploadFile是pdf文件。

data1.append(" file",this.onuploadFile," mypdf"); data1.append(" options"," {\" extraction \":{\" headerFields \":[\" documentNumber \",\" taxId \",\" taxName \",\" purchaseOrderNumber \",\" shippingAmount \",\" netAmount \",\" senderAddress \",\" senderName \",\" grossAmount \",\" currencyCode \",\" receiverContact \",\" documentDate \",\" taxAmount \ ",\" taxRate \",\" receiverName \",\" receiverAddress \"],\" lineItemFields \":[\" description \",\" netAmount \",\" quantity \",\" unitPrice \ ",\" materialNumber \"]},\" clientId \":\" c_00 \",\" documentType \":\" invoice \",\" enrichment \":{\" sender \":{\" top \":5,\" type \":\" businessEntity \",\" subtype \":\"供应商\"},\"员工\":{\" type \":\"员工\"} }}");

var settings = {" url":"/img/DIC_trial_API/document/jobs"," method":" POST"," timeout":0," headers":{" Authorization":" Bearer" + bearerToken}, " processData":false," mimeType":" multipart/form-data"," contentType":false," data":data1};

$。ajax(settings).done(function(response){console.log(response);});

响应为" 400错误",消息为" {"错误":{"代码":" 4","消息":"未提供所需的表单数据。","详细信息":[{ 代码":" 0","消息":"选项"}]}}"。

如果formdata或post调用方法有任何问题,谁能帮忙?

7条回答
clever101
2020-08-14 11:32 .采纳回答

你好Ramesh,

您可以在将JSON添加到表单之前尝试对其进行字符串化吗?

以下代码在这里可以正常工作:

 var form = new FormData($('#fileinfo')[0]);
                 form.append('file',$('input [type = file]')[0] .files [0]);

                 var options = {
                     "提取":{
                         " headerFields":[
                             " taxId",
                             " taxName",
                             "订购单号码",
                             "运费",
                             "净额",
                             " senderAddress",
                             "发件人名称",
                             "总金额",
                             "货币代码",
                             " receiverContact",
                             "税额",
                             "税率",
                             "收件者姓名",
                             " receiverAddress",
                             "邮寄日期",
                             "付款条件",
                             " senderBankAccount"
                         ],
                         " lineItemFields":[
                             "描述",
                             "净额",
                             "数量",
                             "单价",
                             " materialNumber"
                         ]
                     },
                     " clientId":" c_00",
                     " documentType":"发票",
                     " receivedDate":" 2020-02-17",
                     "浓缩":{
                         "发送者":{
                             "前5,
                             " type":" businessEntity",
                             " subtype":"供应商"
                         },
                         "员工":{
                             "类型":"雇员"
                         }
                     }
                 };

                 stringified_options = JSON.stringify(选项)
                 console.log(stringified_options)

                 form.append(" options",stringified_options);

                 var settings = {
                     " url":" http://XXXXXXXXX/document-information-extraction/v1/document/jobs",
                     " method":" POST",
                     "超时":0,
                     "标题":{
                         "授权":"承载者{{token}}"
                     },
                     " processData":否,
                     " mimeType":"多部分/表单数据",
                     " contentType":否,
                     "数据":表格
                 };

                 $ .ajax(settings).done(function(response){
                     console.log(response);
                 });


  

最诚挚的问候
Tobias

一周热门 更多>