新手学习做七牛云上传视频的时候 报错如下,麻烦哪位大神抽空帮我检查下、感激不尽:
java.net.SocketTimeoutException: timeout
...
...
...
Caused by: java.net.SocketException: Socket closed
我的代码:
/**
* 视频上传
* @param filePath
* @return
*/
public Map uploadMp4(String filePath){
//密钥配置
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
//mp4重命名
String key = new QNiuTools().getKeyByName("mp4")+".mp4";
System.out.println("key:"+key);
//上传凭证
String upTaken = auth.uploadToken(SCOPE1,key,3600,null,true);
System.out.println("upTaken:"+upTaken);
try {
//创建上传对象
UploadManager uploadManager = new UploadManager();
Map map = new HashMap();
//OkHttpClient client = new OkHttpClient();
//client.setConnectTimeout(5, TimeUnit.MINUTES);
//client.setReadTimeout(5,TimeUnit.MINUTES);
//client.setWriteTimeout(5,TimeUnit.MINUTES);
//调用put方法上传
Response res = uploadManager.put(filePath, key, upTaken);
//uploadManager.put(new File(filePath),key,upTaken);
String fileName = key.substring(key.lastIndexOf("/")+1,key.length()) ;
map.put("fileName",fileName);
map.put("info","http://"+SCOPE_DOMAIN1+"/");
map.put("path",key.substring(0,key.lastIndexOf("/")+1));
System.out.println(map.get("info")+""+key);
System.out.println("===================");
return map;
} catch (QiniuException e) {
e.printStackTrace();
}
return null;
}
我要碰到类似问题,只不过是在大量上传图片时发生。