好的,我想通过POST将文件发送到服务器。我正在使用像这样的angular2函数
upload() {
let inputEl = this.el.nativeElement.firstElementChild;
if (inputEl.files.length == 0) return;
let files :FileList = inputEl.files;
const formData = new FormData();
for(var i = 0; i < files.length; i++){
formData.append(files[i].name, files[i]);
}
this.http
.post('MyURL', formData)
.subscribe();
}
import { BaseRequestOptions } from '@angular/http';
请求的选项 export class DefaultRequestOptions扩展BaseRequestOptions { constructor(){ 超(); this.headers.append(&#39;内容类型&#39;&#39;多部分/格式数据&#39); this.headers.append(&#39;接受&#39;&#39;应用/ JSON&#39); } }
我想做的事情是
curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' 'MyUrl'
错误看起来像这样
Request URL:MyUrl
Request Method:POST
Status Code:500 Internal Server Error
Remote Address:35.154.2.84:80
Connection:close
Content-Encoding:gzip
Content-Length:1049
Content-Type:application/json;charset=UTF-8
Date:Thu, 17 Nov 2016 21:15:39 GMT
Server:Apache-Coyote/1.1
Vary:Accept-Encoding
Request Header view source
accept:application/json
Accept-Encoding:gzip, deflate
Accept-Language:pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4,fi;q=0.2
Connection:keep-alive
Content-Length:80082
content-type:Multipart/form-data
Host:MyUrl
Origin:http://evil.com/
Request Payload
------WebKitFormBoundaryZXAikA6v0FHYrYii
Content-Disposition: form-data; name="sku-test2.xls";
filename="sku- test2.xls"
Content-Type: application/octet-stream
------WebKitFormBoundaryZXAikA6v0FHYrYii--
我不知道如果问题出在那个formData.append或代码中有什么问题。感谢帮助。
编辑:
码
:
&#34; UNKNOWN_ERROR&#34;
描述
:
&#34; org.springframework.web.multipart.MultipartException:
无法解析多部分servlet请求;嵌套异常是java.io.IOException:org.apache.tomcat.util.http.fileupload.FileUploadException:请求被拒绝,因为没有找到多部分边界↵
在org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:111)↵
在org.springframework.web.multipart.support.StandardMultipartHttpServletRequest。(StandardMultipartHttpServletRequest.java:85)↵
在org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:76)↵
在org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1089)↵在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:928)↵在org.springframework.web.servlet.DispatcherServlet .doService(DispatcherServlet.java:893)↵在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)↵在org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)↵在javax.servlet.http.HttpServlet.service(HttpServlet.java:648)↵在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)↵在javax.servlet.http.HttpServlet.service(HttpServlet) .java:729)↵at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)↵at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)↵atorg.apache .tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)↵在org .apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)↵at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)↵at org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:213)↵在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)↵在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)↵在org .apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)↵在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)↵在org.apache.catalina.valves.RemoteIpValve.invoke (RemoteIpValve.java:676)↵在org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)↵在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)↵在org .apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)↵atorg.a pache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)↵at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:670)↵atorg.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1520)↵在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1476)↵在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1142)↵在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)↵在org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)↵在java。 lang.Thread.run(Thread.java:745)↵原因:java.io.IOException:org.apache.tomcat.util.http.fileupload.FileUploadException:请求被拒绝,因为在org上没有找到多部分边界。 apache.catalina.connector.Request.parseParts(Request.java:2856)↵在org.apache上的org.apache.catalina.connector.Request.getParts(Request.java:2692)↵。 catalina.connector.RequestFacade.getParts(RequestFacade.java:1083)↵at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:92)↵...32more↵原因:org.apache。 tomcat.util.http.fileupload.FileUploadException:请求被拒绝,因为没有找到多部分边界↵在org.apache.tomcat.util.http.fileupload.FileUploadBase $ FileItemIteratorImpl。(FileUploadBase.java:840)↵在org.apache .tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:256)↵at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:280)↵at org.apache.catalina .connector.Request.parseParts(Request.java:2784)↵... 35多↵&#34;
错误
:
[]
信息
:
&#34;内部错误&#34;
在此处输入代码
在这里输入代码