- Notifications
You must be signed in to change notification settings - Fork3k
文件上传增加S3协议的OSS支持#328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
liujiang157 wants to merge9 commits intohs-web:masterChoose a base branch fromliujiang157:feature/oss-support
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
文件上传增加S3协议的OSS支持#328
Changes from1 commit
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
fe9da58 文件上传增加S3协议的OSS支持
liujiang15728e1325 解耦两种文件上传方式的的Configuration
liujiang157d9fece3 提交上传流的返回路径
liujiang15772c89ca 补齐文件流上传测试
liujiang157a5c1e7d 调整代码
liujiang157a491553 新增S3FileProperties
liujiang157ec8edfa 修改代码规范问题
liujiang157947c695 提交UriComponentsBuilder构建url
liujiang1576e7dd9e 修改上传static文件逻辑
liujiang157File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
提交UriComponentsBuilder构建url
采用buffer.asInputStream访问文件移除冗余代码
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit947c6954d4f285b2f781f6a48f0a9bccbc651b90
There are no files selected for viewing
12 changes: 0 additions & 12 deletions...tem/hsweb-system-file/src/main/java/org/hswebframework/web/file/FileUploadProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
46 changes: 29 additions & 17 deletions...b-system-file/src/main/java/org/hswebframework/web/file/service/S3FileStorageService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,13 +5,15 @@ | ||
| import org.hswebframework.web.file.S3FileProperties; | ||
| import org.springframework.core.io.buffer.DataBufferUtils; | ||
| import org.springframework.http.codec.multipart.FilePart; | ||
| import org.springframework.web.util.UriComponentsBuilder; | ||
| import reactor.core.publisher.Mono; | ||
| import reactor.core.scheduler.Schedulers; | ||
| import software.amazon.awssdk.core.sync.RequestBody; | ||
| import software.amazon.awssdk.services.s3.S3Client; | ||
| import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
| import java.io.ByteArrayInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.Locale; | ||
| import java.util.UUID; | ||
| @@ -26,23 +28,22 @@ public class S3FileStorageService implements FileStorageService { | ||
| @Override | ||
| public Mono<String> saveFile(FilePart filePart) { | ||
| String filename = buildFileName(filePart.filename()); | ||
| return DataBufferUtils.join(filePart.content()) | ||
liujiang157 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| .flatMap(dataBuffer -> { | ||
| try (InputStream inputStream = dataBuffer.asInputStream(true)) { | ||
liujiang157 marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| PutObjectRequest request = PutObjectRequest.builder() | ||
| .bucket(properties.getBucket()) | ||
| .key(filename) | ||
| .build(); | ||
| s3Client.putObject(request, RequestBody.fromInputStream(inputStream, dataBuffer.readableByteCount())); | ||
| return Mono.just(buildFileUrl(filename)); | ||
| } catch (IOException e) { | ||
| return Mono.error(e); | ||
| } | ||
| }) | ||
| .subscribeOn(Schedulers.boundedElastic()); | ||
| } | ||
| @@ -73,8 +74,19 @@ private String buildFileName(String originalName) { | ||
| private String buildFileUrl(String key) { | ||
| if (properties.getBaseUrl() != null && !properties.getBaseUrl().isEmpty()) { | ||
liujiang157 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| return UriComponentsBuilder | ||
| .fromUriString(properties.getBaseUrl()) | ||
| .pathSegment(key) | ||
| .build() | ||
| .toUriString(); | ||
| } | ||
| String host = properties.getBucket() + "." + properties.getEndpoint().replaceFirst("^https?://", ""); | ||
| return UriComponentsBuilder | ||
| .newInstance() | ||
| .scheme("https") | ||
| .host(host) | ||
| .pathSegment(key) | ||
| .build() | ||
| .toUriString(); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.