LocalFileServiceImpl.java
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.bs.fileservice.service.impl;
import com.bs.common.config.BsChatConfig;
import com.bs.fileservice.service.IFileService;
import com.bs.fileservice.utils.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
/**
* 本地文件存储
*
* @author leejoker
*/
@Service
@ConditionalOnProperty(prefix = "bs.file", value = "object", havingValue = "local")
public class LocalFileServiceImpl implements IFileService {
@Autowired
private BsChatConfig BsChatConfig;
/**
* 本地文件上传接口
*
* @param file 上传的文件
* @return 访问地址
* @throws Exception
*/
@Override
public String uploadFile(MultipartFile file) throws Exception {
return BsChatConfig.getFile().getCos().getCosImgUrlPrefix()
+FileUploadUtils.upload(BsChatConfig.getFile().getCos().getBucketName(), file);
}
}