|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public String uploadByInputStream(InputStream inputStream) { | 
|---|
|  |  |  | OSS ossClient = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | CredentialsProvider credentialsProvider = new DefaultCredentialProvider(OssConfig.ACCESS_KEY_ID, OssConfig.ACCESS_KEY_SECRET); | 
|---|
|  |  |  | String region = "cn-chengdu"; | 
|---|
|  |  |  | // 创建OSSClient实例。 | 
|---|
|  |  |  | ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration(); | 
|---|
|  |  |  | clientBuilderConfiguration.setSignatureVersion(SignVersion.V4); | 
|---|
|  |  |  | ossClient = OSSClientBuilder.create() | 
|---|
|  |  |  | .endpoint(OssConfig.UPLOAD_ENDPOINT) | 
|---|
|  |  |  | .credentialsProvider(credentialsProvider) | 
|---|
|  |  |  | .clientConfiguration(clientBuilderConfiguration) | 
|---|
|  |  |  | .region(region) | 
|---|
|  |  |  | .build(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String fileExt = "png"; | 
|---|
|  |  |  | String fileName = UUID.randomUUID().toString(); | 
|---|
|  |  |  | // 设置文件名 | 
|---|
|  |  |  | String filePathName = generateRelativeStoragePath(OssConfig.FOLDER, fileExt, fileName); | 
|---|
|  |  |  | // 创建PutObjectRequest对象。 | 
|---|
|  |  |  | PutObjectRequest putObjectRequest = new PutObjectRequest(OssConfig.BUCKET_NAME, filePathName, inputStream); | 
|---|
|  |  |  | // 创建PutObject请求。 | 
|---|
|  |  |  | PutObjectResult result = ossClient.putObject(putObjectRequest); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return OssConfig.DOWNLOAD_ENDPOINT + filePathName; | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | ossClient.shutdown(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <pre> | 
|---|
|  |  |  | * 获取存储的相对路径 | 
|---|