gpt4 book ai didi

image - 使用 Jersey 客户端上传图像文件时服务器出现异常

转载 作者:行者123 更新时间:2023-12-05 04:14:19 26 4
gpt4 key购买 nike

我正在尝试使用 jersey 客户端将图像文件发送到服务器。我在服务器中遇到以下错误

我从我的客户端应用程序打开存储在本地驱动程序中的文件,并使用 jersey 客户端 API 将其传递。

    Feb 06, 2016 7:38:09 AM org.jvnet.mimepull.TempFiles createTempFile
SEVERE: Exception caught
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jvnet.mimepull.TempFiles.createTempFile(TempFiles.java:139)
at org.jvnet.mimepull.MemoryData.createNext(MemoryData.java:96)
at org.jvnet.mimepull.Chunk.createNext(Chunk.java:64)
at org.jvnet.mimepull.DataHead.addBody(DataHead.java:87)
at org.jvnet.mimepull.MIMEPart.addBody(MIMEPart.java:231)
at org.jvnet.mimepull.MIMEMessage.makeProgress(MIMEMessage.java:240)
at org.jvnet.mimepull.MIMEMessage.parseAll(MIMEMessage.java:181)
at org.jvnet.mimepull.MIMEMessage.getAttachments(MIMEMessage.java:106)
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readMultiPart
(MultiPartReaderClientSide.java:205)
at com.sun.jersey.multipart.impl.MultiPartReaderServerSide.readMultiPart
(MultiPartReaderServerSide.java:80)
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(Mult
iPartReaderClientSide.java:158)
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(Mult
iPartReaderClientSide.java:85)
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequ
est.java:490)
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequ
est.java:555)
at com.sun.jersey.multipart.impl.FormDataMultiPartDispatchProvider$FormD
ataInjectableValuesProvider.getInjectableValues(FormDataMultiPartDispatchProvide
r.java:122)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMeth
odDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatch
Provider.java:153)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMeth
odDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchPr
ovider.java:203)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDi
spatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethod
Rule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHa
ndPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(Resourc
eClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHa
ndPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(R
ootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequ
est(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequ
est(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleReque
st(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleReque
st(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponen
t.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(Servlet
Container.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(Servlet
Container.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52
)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:620)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpo
int.java:2476)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoin
t.java:2465)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskTh
read.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.nio.file.NoSuchFileException: D:\personal\apache-tomcat-7.0.61\t
emp\MIME8685830544490166217.tmp
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source)
at java.nio.file.Files.newByteChannel(Unknown Source)
at java.nio.file.Files.createFile(Unknown Source)
at java.nio.file.TempFileHelper.create(Unknown Source)
at java.nio.file.TempFileHelper.createTempFile(Unknown Source)
at java.nio.file.Files.createTempFile(Unknown Source)
... 56 more

Feb 06, 2016 7:38:09 AM org.jvnet.mimepull.TempFiles createTempFile
WARNING: Error invoking java.nio API, temp file (path: null, prefix:MIME, suffix
:null) being created using old java.io API.
java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createTempFile(Unknown Source)
at org.jvnet.mimepull.TempFiles.createTempFile(TempFiles.java:152)
at org.jvnet.mimepull.MemoryData.createNext(MemoryData.java:96)
at org.jvnet.mimepull.Chunk.createNext(Chunk.java:64)
at org.jvnet.mimepull.DataHead.addBody(DataHead.java:87)
at org.jvnet.mimepull.MIMEPart.addBody(MIMEPart.java:231)
at org.jvnet.mimepull.MIMEMessage.makeProgress(MIMEMessage.java:240)
at org.jvnet.mimepull.MIMEMessage.parseAll(MIMEMessage.java:181)
at org.jvnet.mimepull.MIMEMessage.getAttachments(MIMEMessage.java:106)
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readMultiPart
(MultiPartReaderClientSide.java:205)
at com.sun.jersey.multipart.impl.MultiPartReaderServerSide.readMultiPart
(MultiPartReaderServerSide.java:80)
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(Mult
iPartReaderClientSide.java:158)
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(Mult
iPartReaderClientSide.java:85)
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequ
est.java:490)
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequ
est.java:555)
at com.sun.jersey.multipart.impl.FormDataMultiPartDispatchProvider$FormD
ataInjectableValuesProvider.getInjectableValues(FormDataMultiPartDispatchProvide
r.java:122)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMeth
odDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatch
Provider.java:153)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMeth
odDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchPr
ovider.java:203)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDi
spatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethod
Rule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHa
ndPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(Resourc
eClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHa
ndPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(R
ootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequ
est(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequ
est(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleReque
st(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleReque
st(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponen
t.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(Servlet
Container.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(Servlet
Container.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52
)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
AbstractProtocol.java:620)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpo
int.java:2476)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoin
t.java:2465)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskTh
read.java:61)
at java.lang.Thread.run(Unknown Source)

我的服务器代码:

 @POST
@Path("/image")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
public Response uploadFile(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) {
System.out.println("XXXXXXXXXXXXXXXXXXXXXX");
TransactionHandler th = new TransactionHandlerImpl();
boolean bol = th.saveFiletoDisk(uploadedInputStream,4545);
if(bol){
return Response.ok().build();
}else{
return Response.noContent().build();
}
}

客户电话

public boolean uploadImage(long id){
FileInputStream fis = null;
boolean returnval = false;
ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
Client client = Client.create(cc);
WebResource service = client.resource(Util.getServerIPAddress() + "/pos-1/rest");

File file = new File("\\myphotos\\images\\"+id + ".png");
FormDataMultiPart multipart = new FormDataMultiPart();
multipart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
multipart.bodyPart(new FileDataBodyPart("file", file, MediaType.APPLICATION_OCTET_STREAM_TYPE));
ClientResponse response = service.path("image").type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class,multipart);
if(response.getStatus() == 200){
returnval = true;
}
return returnval;
}

最佳答案

来自错误:

java.nio.file.NoSuchFileException: D:\personal\apache-tomcat-7.0.61\t
emp\MIME8685830544490166217.tmp

路径 D:\personal\apache-tomcat-7.0.61\temp 不存在。创建临时目录。它应该有效。

遇到了同样的问题。并通过上述方式解决。

来源:https://www.garysieling.com/blog

关于image - 使用 Jersey 客户端上传图像文件时服务器出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35236570/

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