aliyun/aliyun-oss-java-sdk

图品url设置私有,但是浏览器依然可以访问,需要关闭浏览器才生效

yuzhoufengg2 opened this issue · 0 comments

private boolean setFileAcl(String appKey, String appSecret, String bucketName, String url, FileReadType type) {
OSSClient client = this.getOssClient(appKey, appSecret);
if (client != null) {
try {
// 公转私时,指定的目录不允许转
if (type == FileReadType.PRIVATE_TYPE) {
boolean urlPathCanSetFileAcl = this.checkUrlPathCanSetFileAcl(url);
if (!urlPathCanSetFileAcl) {
return false;
}
}
String fileName = this.getFileName(this.handleRemoveUrlParams(url));
if (fileName == null) {
return false;
}
boolean found = client.doesObjectExist(bucketName, fileName);
if (!found) {
//文件不存在
return false;
}
CannedAccessControlList cannedACL = CannedAccessControlList.Default;
if (type == FileReadType.PUBLIC_READ_ONLY_TYPE) {
cannedACL = CannedAccessControlList.PublicRead;
// 处理contentType
this.handleFileContentType(appKey, appSecret, bucketName, fileName);
} else if (type == FileReadType.PRIVATE_TYPE) {
cannedACL = CannedAccessControlList.Private;
}
// 设置文件的访问权限。
client.setObjectAcl(bucketName, fileName, cannedACL);
return true;
} catch (Exception e) {
logger.error("setFileAcl Exception: ", e);
client.shutdown();
ossClientMap.remove(this.getOssKey(appKey, appSecret));
return false;
}
}
return false;
}