public static String upload2Oss(String imgurl,String path){
OSSClient client = OssUtils.getOSSClient();
String filepath=path+"/"+sdf.format(new Date())+"/"+MD5.MD5(System.currentTimeMillis()+"")+".jpg";
long start=System.currentTimeMillis();
URL url;
InputStream is =null;
HttpURLConnection httpUrlConn =null;
try {
url = new URL(imgurl);
// URLConnection con = url.openConnection();
httpUrlConn = (HttpURLConnection) url.openConnection();
httpUrlConn.setConnectTimeout(5000);
httpUrlConn.setDoInput(true);
httpUrlConn.setRequestMethod("GET");
httpUrlConn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
// 获取输入流
is = httpUrlConn.getInputStream();
client.putObject("playerpark", filepath, is);
} catch (Exception e) {
LOG.info("上传失败的URL:"+imgurl);
e.printStackTrace();
return "";
}finally{
if(is!=null){
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(httpUrlConn!=null){
httpUrlConn.disconnect();
}
}
LOG.info("上传一张图片到阿里云时间:"+(System.currentTimeMillis()-start));
return filepath;
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。