1、我运行如下代码时报的错是:Exception in thread "main" [ErrorCode]:AccessDenied, [Message]:The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
代码:
String accessKeyId = "申请的id";
String accessKeySecret = "申请的key";
OSSClient client = new OSSClient(accessKeyId, accessKeySecret);
String bucketName="yskjtest";//此bucket已经存在
// 获取指定文件的输入流
String filePath="f:\\osstest\\btre.jpg";
File file = new File(filePath);
try {
InputStream content = new FileInputStream(file);
// 创建上传 Object 的 Metadata
ObjectMetadata meta = new ObjectMetadata();
// 必须设置 ContentLength
meta.setContentLength(file.length());
// 上传 Object.
PutObjectResult result = client.putObject(bucketName, "newphoto.jpg", content, meta);
// 打印 ETag
System.out.println(result.getETag());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
2、我运行如下代码报错信息:Exception in thread "main" [ErrorCode]:InvalidBucketName, [Message]:The specified bucket is not valid.
代码:
String accessKeyId = "申请的id";
String accessKeySecret = "申请的key";
OSSClient client = new OSSClient(accessKeyId, accessKeySecret);
String bucketName="yskjtest";//此bucket已经存在
String endpoint = "http://yskjtest.oss-cn-beijing.aliyuncs.com";
OSSClient client = new OSSClient(endpoint,accessKeyId, accessKeySecret);
// 获取指定文件的输入流
String filePath="f:\\osstest\\btre.jpg";
File file = new File(filePath);
try {
InputStream content = new FileInputStream(file);
// 创建上传 Object 的 Metadata
ObjectMetadata meta = new ObjectMetadata();
// 必须设置 ContentLength
meta.setContentLength(file.length());
// 上传 Object.
PutObjectResult result = client.putObject(bucketName, "newphoto.jpg", content, meta);
// 打印 ETag
System.out.println(result.getETag());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
到底该怎么写啊,求大神指教
-------------------------
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。