| | |
| | | // 上传文件到 Minio |
| | | this.ossService.putObject(bucket, objectName, inputStream, contentType); |
| | | |
| | | // ✅ 拼接永久 URL(不带 presigned 过期参数) |
| | | String baseUrl = OssConfiguration.endpoint; |
| | | if (!baseUrl.endsWith("/")) { |
| | | baseUrl += "/"; |
| | | } |
| | | |
| | | return baseUrl + bucket + "/" + objectName; |
| | | return buildUrl(bucket, objectName); |
| | | } catch (Exception e) { |
| | | throw new IOException("Upload failed: " + e.getMessage(), e); |
| | | } |
| | |
| | | |
| | | public String upload(String bucket, String objectKey, InputStream input) { |
| | | try { |
| | | |
| | | // 上传文件 |
| | | this.ossService.putObject(bucket, objectKey, input); |
| | | |
| | | // ✅ 构建永久访问 URL |
| | | String baseUrl = OssConfiguration.endpoint; |
| | | if (!baseUrl.endsWith("/")) { |
| | | baseUrl += "/"; |
| | | } |
| | | return baseUrl + bucket + "/" + objectKey; |
| | | return buildUrl(bucket, objectKey); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("Upload failed: " + e.getMessage(), e); |
| | | } |
| | | } |
| | | @Async("threadPoolTaskExecutor") |
| | | |
| | | public String upload(String bucket, String objectKey, InputStream input, String contentType) { |
| | | try { |
| | | // 上传文件时指定 Content-Type |
| | | this.ossService.putObject(bucket, objectKey, input, contentType); |
| | | |
| | | // ✅ 构建永久访问 URL |
| | | String baseUrl = OssConfiguration.endpoint; |
| | | if (!baseUrl.endsWith("/")) { |
| | | baseUrl += "/"; |
| | | } |
| | | return baseUrl + bucket + "/" + objectKey; |
| | | return buildUrl(bucket, objectKey); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("Upload failed: " + e.getMessage(), e); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // 构建url |
| | | private String buildUrl(String bucket, String key) { |
| | | String base = OssConfiguration.endpoint; |
| | | if (!base.endsWith("/")) { |
| | | base += "/"; |
| | | } |
| | | return base + bucket + "/" + key; |
| | | } |
| | | |
| | | } |