gpt4 book ai didi

java - Azure 逻辑应用程序 http post multipart/form-data 文件上传

转载 作者:行者123 更新时间:2023-12-02 12:16:57 70 4
gpt4 key购买 nike

我正在尝试使用 Azure 中的 HTTP 逻辑应用调用 api

我可以通过 postman 使通话成功。查看我的帖子人配置

Post Man Configuration

我可以看到来自 postman 的http代码,我使用它来使逻辑应用程序的格式类似于 postman 的格式。

POST /dcma/rest/initiateOcrClassifyExtract HTTP/1.1

Host: godemo.ephesoft.com

Authorization: Basic NDU=??????

Cache-Control: no-cache

Postman-Token: 3baf23e7-6b46-a5f4-094b-3df1879bbe21

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="000001.pdf"; filename="000001.pdf"
Content-Type: application/pdf


------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="batchClassIdentifier"

BC590

------WebKitFormBoundary7MA4YWxkTrZu0gW--

下面是实际的逻辑应用 http 配置。

Logic App config

服务器上的日志显示以下错误

    2017-09-07 20:12:51,784 [ajp-apr-8009-exec-3] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/dcma].[DispatcherServlet]- Servlet.service() for servlet [DispatcherServlet] in context with path [/dcma] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: Header section has more than 10240 bytes (maybe it is not properly terminated)] with root cause
org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Header section has more than 10240 bytes (maybe it is not properly terminated)
at org.apache.commons.fileupload.MultipartStream.readHeaders(MultipartStream.java:541)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:999)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:965)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:158)
at org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:142)
at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1070)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:912)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.ephesoft.dcma.webapp.AuthenticationFilter.doFilter(AuthenticationFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.ephesoft.dcma.webapp.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:230)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.ephesoft.dcma.webapp.HTTPHeaderFilter.doFilter(HTTPHeaderFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)

最佳答案

对于 multipart/form-data,官方文档中有一个示例:

https://learn.microsoft.com/bs-latn-ba/azure/connectors/connectors-native-http#content-with-multipartform-data-type

"body": {
"$content-type": "multipart/form-data",
"$multipart": [
{
"body": "<output-from-trigger-or-previous-action>",
"headers": {
"Content-Disposition": "form-data; name=file; filename=<file-name>"
}
}
]
}

如果还有其他表单字段要发送,只需添加具有正确表单字段名称的类似对象即可。

如果您没有使用上一步中的 TriggerBody,Content-Disposition header 将需要对 namefilename 字段进行转义引号。

"Content-Disposition": "form-data; name=\"file\"; filename=\"<file-name>\""

关于java - Azure 逻辑应用程序 http post multipart/form-data 文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46104643/

70 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com