「已注销」 2018-06-12 01:32 采纳率: 100%
浏览 4145
已采纳

OSS循环上传30多个文件, 有一个文件显示上传超时,其他都成功了

代码如下:

// 上传文件
private static void uploadFile(OSSClient client, String bucketName, String key, File file)
        throws OSSException, ClientException, IOException {

    ObjectMetadata objectMeta = new ObjectMetadata();
    objectMeta.setContentLength(file.length());
    String fileName=key.substring(key.lastIndexOf("."));
    if(fileName.equalsIgnoreCase(".pdf")) {
        objectMeta.setContentType("application/pdf");
    }else if(fileName.equalsIgnoreCase(".zip")){
        objectMeta.setContentType("application/octet-stream");
    }else{
        // 可以在metadata中标记文件类型
        objectMeta.setContentType("image/jpeg");
    }
    InputStream input = new FileInputStream(file);
   client.putObject(bucketName, key, input, objectMeta);
    input.close();

}

控制台输出如下:

12-Jun-2018 09:18:44.694 警告 [http-nio-8084-exec-7] com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl Unable to execute HTTP request: Read timed out

12-Jun-2018 09:19:37.353 警告 [http-nio-8084-exec-7] com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl Unable to execute HTTP request: Read timed out

2018-06-12 09:19:37.368 | UPLOAD FILE ERROR !
com.aliyun.oss.ClientException: Read timed out

at com.aliyun.oss.common.utils.ExceptionFactory.createNetworkException(ExceptionFactory.java:65) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:62) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:126) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:72) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:92) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:133) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:111) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.aliyun.oss.internal.OSSObjectOperation.writeObjectInternal(OSSObjectOperation.java:518) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.aliyun.oss.internal.OSSObjectOperation.putObject(OSSObjectOperation.java:112) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.aliyun.oss.OSSClient.putObject(OSSClient.java:407) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.aliyun.oss.OSSClient.putObject(OSSClient.java:394) ~[aliyun-sdk-oss-2.0.5.jar:na]
at com.tmbj.api.service.imgupload.UploadService.uploadFile(UploadService.java:104) ~[classes/:na]
at com.tmbj.api.service.imgupload.UploadService.upload(UploadService.java:39) ~[classes/:na]
at com.tmbj.api.service.imgupload.UploadService$$EnhancerByCGLIB$$487d1c8f.CGLIB$upload$0(<generated>) [cglib-nodep-3.1.jar:na]
at com.tmbj.api.service.imgupload.UploadService$$EnhancerByCGLIB$$487d1c8f$$FastClassByCGLIB$$3380697a.invoke(<generated>) [cglib-nodep-3.1.jar:na]
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) [cglib-nodep-3.1.jar:na]
at com.jfinal.aop.Invocation.invoke(Invocation.java:82) [classes/:na]
at com.jfinal.aop.Callback.intercept(Callback.java:96) [classes/:na]
at com.tmbj.api.service.imgupload.UploadService$$EnhancerByCGLIB$$487d1c8f.upload(<generated>) [cglib-nodep-3.1.jar:na]
at com.tmbj.api.controller.TmInsureFenqiController.setContractValue(TmInsureFenqiController.java:1305) [classes/:na]
at com.tmbj.api.controller.TmInsureFenqiController.createLoadContract(TmInsureFenqiController.java:998) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_151]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_151]
at com.jfinal.aop.Invocation.invoke(Invocation.java:73) [classes/:na]
at com.tmbj.api.session.CorsInterceptor.intercept(CorsInterceptor.java:35) [classes/:na]
at com.jfinal.aop.Invocation.invoke(Invocation.java:67) [classes/:na]
at com.tmbj.api.exception.TmbjExceptionInterceptor.intercept(TmbjExceptionInterceptor.java:28) [classes/:na]
at com.jfinal.aop.Invocation.invoke(Invocation.java:67) [classes/:na]
at com.tmbj.api.session.SessionInterceptor.intercept(SessionInterceptor.java:39) [classes/:na]
at com.jfinal.aop.Invocation.invoke(Invocation.java:67) [classes/:na]
at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74) [classes/:na]
at com.jfinal.ext.handler.UrlSkipHandler.handle(UrlSkipHandler.java:45) [classes/:na]
at com.jfinal.plugin.druid.DruidStatViewHandler.handle(DruidStatViewHandler.java:75) [classes/:na]
at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72) [classes/:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:8.5.31]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:8.5.31]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [catalina.jar:8.5.31]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:8.5.31]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) [catalina.jar:8.5.31]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [catalina.jar:8.5.31]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [catalina.jar:8.5.31]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) [catalina.jar:8.5.31]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [catalina.jar:8.5.31]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [catalina.jar:8.5.31]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-coyote.jar:8.5.31]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:8.5.31]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-coyote.jar:8.5.31]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468) [tomcat-coyote.jar:8.5.31]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:8.5.31]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_151]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_151]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.5.31]

at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]

  • 写回答

2条回答 默认 最新

  • Fatal Error 2018-06-12 01:41
    关注

    超时可能是网络原因引起的,这种文件上传的逻辑建议增加重传机制,可以使用生产者-消费者模式,对于上传失败的重新扔回队列,让消费者尝试重新上传。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 VB.NET2022如何生成发布成exe文件
  • ¥30 matlab appdesigner私有函数嵌套整合
  • ¥15 给我一个openharmony跑通webrtc实现视频会议的简单demo项目,sdk为12
  • ¥15 vb6.0使用jmail接收smtp邮件并另存附件到D盘
  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印