/**
* 文件流上传图片
/**
* 文件流上传图片
* @param fileInputStream
* @param dirName
* @return
* @throws ForbiddenException
*/
public String uploadImageStream(InputStream fileInputStream, String dirName) throws ForbiddenException {
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
// 生成随机文件名称
long snowflakeId= idGenerator.snowflakeId();
String uploadFileName = dirName + "/" + snowflakeId + ".png";
PutObjectResult putObjectResult = ossClient.putObject(bucketName, uploadFileName, fileInputStream);
String ossPath = "https://" + bucketName + "." + endpoint + "/" + uploadFileName;
log.info("文件上传成功!==>" + ossPath);
return ossPath;
} catch (Exception e) {
e.printStackTrace();
throw new ForbiddenException("Aliyun Oss upload fail");
} finally {
// 关闭OSSClient。
ossClient.shutdown();
}
}