开发者社区> 问答> 正文

关于oss上传问题来位大虾帮我瞅瞅


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)

展开
收起
旺财小强 2015-12-08 15:07:12 11598 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载