public class OssTest {
public static void main(String[] args){
try{
String accessKeyId =
"";
String accessKeySecret =
"";
String endpoint =
"https://oss-cn-shanghai-internal.aliyuncs.com";
OSSClient client =
new OSSClient(endpoint, accessKeyId, accessKeySecret);
System.
out.println(
"client is build!");
//
[font='宋体']上传文件流
[font='宋体']
//
[font='宋体']上传字符串
[font='宋体'] String content =
"Hello OSS";
client.putObject(
"ecg-zxyl",
"12312313",
new ByteArrayInputStream(content.getBytes()));
//
[font='宋体']关闭
client
client.shutdown();
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
按照文档编写的例子,ecs服务器和oss都在华东2,同一个区域!如果endpoint修改为外网访问的地址就没有问题。如果为目前的内网地址的话,到了pubObject这一步就出错了异常如下:
om.aliyun.oss.ClientException: ConnectionTimeoutat com.aliyun.oss.common.utils.ExceptionFactory.createNetworkException(ExceptionFactory.java:71)at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:128)at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:123)at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:68)at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:94)at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:149)at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:113)at com.aliyun.oss.internal.OSSObjectOperation.writeObjectInternal(OSSObjectOperation.java:790)at com.aliyun.oss.internal.OSSObjectOperation.putObject(OSSObjectOperation.java:145)at com.aliyun.oss.OSSClient.putObject(OSSClient.java:558)at com.aliyun.oss.OSSClient.putObject(OSSClient.java:540)at com.aliyun.oss.OSSClient.putObject(OSSClient.java:534)at OssTest.main(OssTest.java:34)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。