Closed ggzz11t closed 1 year ago
如标题,在上传图片时设置Acl为AccessControlList.REST_CANNED_PUBLIC_READ,根据图片的url在浏览器访问自动下载了,如何配置可以让图片在浏览器显示而不是下载 ObsClient obsClient = getObsClient(); try { PutObjectRequest request = new PutObjectRequest(); request.setBucketName(bucketName); request.setObjectKey(fileName); request.setInput(new ByteArrayInputStream(content)); // 设置对象访问权限为公共读 request.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ); PutObjectResult response = obsClient.putObject(request); LOGGER.info("文件上传成功 requestId:{}",response.getRequestId()); return ((ObsFSFile) response).getObjectKey(); } catch (ObsException e) { //文件上传失败 LOGGER.error("上传失败:ResponseCode:{}",e.getResponseCode()); LOGGER.error("上传失败:ErrorCode:{}",e.getErrorCode()); LOGGER.error("上传失败:ErrorMessage:{}",e.getErrorMessage()); LOGGER.error("上传失败:ErrorRequestId:{}",e.getErrorRequestId()); LOGGER.error("上传失败:ErrorHostId:{}",e.getErrorHostId()); return ""; } finally { obsClient.close(); }
是由于法规要求导致的,只能通过绑定自定义域名来规避,具体可以看下这里https://support.huaweicloud.com/obs_faq/obs_03_0087.html
如标题,在上传图片时设置Acl为AccessControlList.REST_CANNED_PUBLIC_READ,根据图片的url在浏览器访问自动下载了,如何配置可以让图片在浏览器显示而不是下载 ObsClient obsClient = getObsClient(); try { PutObjectRequest request = new PutObjectRequest(); request.setBucketName(bucketName); request.setObjectKey(fileName); request.setInput(new ByteArrayInputStream(content)); // 设置对象访问权限为公共读 request.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ); PutObjectResult response = obsClient.putObject(request); LOGGER.info("文件上传成功 requestId:{}",response.getRequestId()); return ((ObsFSFile) response).getObjectKey(); } catch (ObsException e) { //文件上传失败 LOGGER.error("上传失败:ResponseCode:{}",e.getResponseCode()); LOGGER.error("上传失败:ErrorCode:{}",e.getErrorCode()); LOGGER.error("上传失败:ErrorMessage:{}",e.getErrorMessage()); LOGGER.error("上传失败:ErrorRequestId:{}",e.getErrorRequestId()); LOGGER.error("上传失败:ErrorHostId:{}",e.getErrorHostId()); return ""; } finally { obsClient.close(); }