百度云存储 BCS 文件上传,权限设置问题
本帖最后由 xiaobluesky 于 2014-01-03 20:37:50 编辑 图片上传的时候,存放在 百度云上,可是上传后,全变成私有,再想在APP里面用,就没法用了。
想在上传的时候设置,公开。
百度云的ACL说明也看了,说的不清不楚的,请各位大神指点。。
public static void putObjectByFile(BaiduBCS baiduBCS, File file)
throws Exception {
System.out.println("1");
PutObjectRequest request = new PutObjectRequest(bucket, objectName, file);
System.out.println("2");
ObjectMetadata metadata = new ObjectMetadata();
System.out.println("3");
request.setMetadata(metadata);
System.out.println("4");
/*测试设置权限,有问题
//statement
Statement statement = new Statement();
statement.addAction(PolicyAction.all);
statement.addUser("*");
statement.addResource(bucket + objectName);
statement.setEffect(PolicyEffect.allow);
//Policy
Policy policy =new Policy();
policy.addStatements(statement);
//设置Policy,这段百度的API 也有问题.
baiduBCS.putObjectPolicy(bucket,objectName, policy);
*/
BaiduBCSResponse<ObjectMetadata> response = baiduBCS.putObject(request);
LogUtils.logi("UploadUtils", "---UploadUtils---result:" + request);
System.out.println("5");
ObjectMetadata objectMetadata = response.getResult();
LogUtils.logi("UploadUtils", "---UploadUtils---result:"
+ objectMetadata);
}
PutObjectRequest request = new PutObjectRequest(bucket, objectName, file);
request.setAcl(X_BS_ACL.PublicRead);