package Utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectResult;
public class demo1 {
public static void main(String[] args ) throws FileNotFoundException {
String accessKeyId = "key";
String accessKeySecret = "secret";
// 以杭州为例
String endpoint = "http://xq.oss-cn-beijing-internal.aliyuncs.com";
// 初始化一个OSSClient
OSSClient client = new OSSClient(endpoint,accessKeyId, accessKeySecret);
//创建一个新的Bucket
client.createBucket("xq");
File file = new File("C:\\psu.jpg");
InputStream content = new FileInputStream(file);
// 创建上传Object的Metadata
ObjectMetadata meta = new ObjectMetadata();
// 必须设置ContentLength
meta.setContentLength(file.length());
// 上传Object.
PutObjectResult result = client.putObject("xq", accessKeyId, content, meta);
// 打印ETag
System.out.println(result.getETag());
}
}
我创建oss客户端一运行就报这样的错误怎么解决?
十二月 08, 2015 2:43:38 下午 com.aliyun.oss logException
警告: [Client]Unable to execute HTTP request: SocketException
Exception in thread "main" com.aliyun.oss.ClientException: SocketException
at com.aliyun.oss.common.utils.ExceptionFactory.createNetworkException(ExceptionFactory.java:68)
at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:67)
at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:121)
at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:67)
at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:89)
at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:130)
at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:108)
at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:103)
at com.aliyun.oss.internal.OSSBucketOperation.createBucket(OSSBucketOperation.java:109)
at com.aliyun.oss.OSSClient.createBucket(OSSClient.java:308)
at com.aliyun.oss.OSSClient.createBucket(OSSClient.java:302)
at Utils.demo1.main(demo1.java:24)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。