|
@@ -106,10 +106,19 @@ public class FileController {
|
|
|
bucket = ossProperties.getBucketName();
|
|
|
}
|
|
|
log.info("==> 下载文档: name={}, bucket={}", name, bucket);
|
|
|
+
|
|
|
+ long size = ossTemplate.getSize(bucket, name);
|
|
|
+
|
|
|
try {
|
|
|
+ if (size < 0) {
|
|
|
+ log.error("文档不存在 name={}, bucket={}", name, bucket);
|
|
|
+ response.getWriter().println("文档 " + name + " 不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
response.setContentType("application/octet-stream");
|
|
|
response.setHeader("Content-Disposition", "attachment;filename*=utf8''" + URLEncodeUtil.encode(name));
|
|
|
- response.setHeader("Content-Length", String.valueOf(ossTemplate.getSize(bucket, name)));
|
|
|
+ response.setHeader("Content-Length", String.valueOf(size));
|
|
|
|
|
|
S3Object s3Object = ossTemplate.getObject(bucket, name);
|
|
|
IoUtil.copy(s3Object.getObjectContent(), response.getOutputStream());
|
|
@@ -140,14 +149,13 @@ public class FileController {
|
|
|
|
|
|
private Pair<Document, DocumentEditParam> docPair(String bucket, String title, String name,
|
|
|
String userId, String userName) {
|
|
|
- String downloadUrl = String.format(DocumentConstants.OFFICE_API_DOC_FILE, serverUrl, name);
|
|
|
- if (StrUtil.isNotBlank(bucket)) {
|
|
|
- downloadUrl += "&bucket=" + bucket;
|
|
|
- }
|
|
|
|
|
|
title = StrUtil.isBlank(title) ? name : title;
|
|
|
bucket = StrUtil.isBlank(bucket) ? ossProperties.getBucketName() : bucket;
|
|
|
|
|
|
+ String downloadUrl = String.format(DocumentConstants.OFFICE_API_DOC_FILE, serverUrl, name);
|
|
|
+ downloadUrl += "&bucket=" + bucket;
|
|
|
+
|
|
|
Document document = Document.builder()
|
|
|
.key(FileNameUtil.getPrefix(name))
|
|
|
.title(title)
|