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

2020-08-14 10:33发布

         点击此处--->   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调用方法有任何问题,谁能帮忙?

         点击此处--->   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
1楼 · 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

Nan4612
2楼-- · 2020-08-14 11:23

Hi Tobias,

感谢您的代码。 因此,在这种情况下,在创建formdata时将使用Fileuploader的form元素。 我正在使用fileuploader和navigator.camera/image控件分别捕获pdf和图像。 表单数据看起来像-

但是,内容类型仍为"文本/纯文本"。

 var data1 = new FormData($('#container-cordova --- View1--fileUploader-fu_form')[0]);
 data1.append(" file",$('input [type = file]')[0] .files [0]);
 data1.append(" options",stringized);
 var settings = {
 " method":'POST',
 " url":"/img/DIC_trial_API/document/jobs",
 "超时":0,
 "标题":{
 "授权":" Bearer" + bearerToken
 },
 " contentType":否,
                                 "数据":data1,
                                 " mimeType":"多部分/表单数据",
 " processData":否
 };
 $ .ajax(settings).done(function(response){
 console.log(response);
 });
 
lukcy2020
3楼-- · 2020-08-14 11:27

嘿Ramesh,

看起来就像邮递员向终端发送东西时创建的示例。
我们有时会看到" multipart/form-data"存在问题。
您能否尝试解决此问题并重试 ?

感谢和问候,
克里斯托夫

SC_Yao
4楼-- · 2020-08-14 11:15

克里斯托夫·嗨,

我在某处读到,如果我们将内容类型设置为未定义,它将根据发送的数据来选择类型。 因此,代码现在看起来像这样-

 jQuery.sap.domById(fileuploader.getId()+" -fu")。setAttribute(" type"," file");  data1.append(" file",jQuery.sap.domById(fileuploader.getId()+" -fu")。files [0]);
 var blob = new Blob([JSON.stringify(options)],{type:'application/json'});
 data1.append(" options",blob);
 jQuery.ajax({url:"/img/DIC_trial_API/document/jobs,data:data1," headers":{" Content-Type":undefined," Authorization":" Bearer" + bearerToken},缓存:false,processData:  false,方法:" POST",
 成功:功能(数据){
 console.log(data);  },
 错误:function(err){console.log(err);  }});
 

然后,将内容类型设置为" application/x-www-form-urlencoded; charset = UTF-8",并且表单数据看起来为空- ty-formdata.jpg

并且,当从swagger UI测试API时,formdata看起来像-

小c菟菟
5楼-- · 2020-08-14 11:30

嗨Ramesh,

这只是一些测试代码,可以尝试一下,不幸的是,我目前没有完整的应用程序。 现在对您有用吗?

最诚挚的问候
Tobias

三十六小时_GS
6楼-- · 2020-08-14 11:32

最后,问题已解决。 我正在使用混合应用程序工具包来捕获图片,这导致了formdata问题。 Fileuploader提供了用于捕获图像的相机选项。 关闭HAT扩展后,它运行良好。 谢谢

风早神人
7楼-- · 2020-08-14 11:12

您好Ramesh,

能帮您建立客户端ID的方法吗?由于客户端ID不存在,我遇到了错误

谢谢

一周热门 更多>