完成上传文件至阿里云接口
This commit is contained in:
parent
2f58a3a85a
commit
aa4baa541b
@ -109,6 +109,12 @@
|
||||
<version>3.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.10.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package com.xhpc.invoice.controller;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.xhpc.common.core.utils.DateUtils;
|
||||
import com.xhpc.common.core.web.controller.BaseController;
|
||||
import com.xhpc.common.core.web.domain.AjaxResult;
|
||||
import com.xhpc.invoice.constant.InvoiceStatusConst;
|
||||
@ -8,12 +10,15 @@ import com.xhpc.invoice.domain.AllInvoiceOrdersResponse;
|
||||
import com.xhpc.invoice.domain.InvoiceToUserRequest;
|
||||
import com.xhpc.invoice.domain.SpecificInvoiceWrap;
|
||||
import com.xhpc.invoice.service.XhpcInvoiceService;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -29,6 +34,32 @@ public class XhpcInvoiceController extends BaseController {
|
||||
|
||||
@Resource
|
||||
XhpcInvoiceService xhpcInvoiceService;
|
||||
@Resource
|
||||
Environment environment;
|
||||
|
||||
/**
|
||||
* 上传图片到阿里云接口
|
||||
*
|
||||
* @param invoicePdf 文件二进制对象
|
||||
* @return 该文件在阿里云中的地址
|
||||
* @author WH
|
||||
* @date 2021/12/29 16:40
|
||||
* @since version-1.0
|
||||
*/
|
||||
@PostMapping("/pdf")
|
||||
public AjaxResult uploadPdf(MultipartFile invoicePdf) throws IOException {
|
||||
|
||||
String filename = "electronicInvoice" + DateUtils.dateTimeNow() + ".pdf";
|
||||
// 上传文件到阿里云
|
||||
OSSClient ossClient = new OSSClient(environment.getProperty("oss.endpoint"), environment.getProperty("oss.access-key"), environment.getProperty("oss.secret-key"));
|
||||
// 放置到哪个块中去,key为目录,file为文件
|
||||
ossClient.putObject(environment.getProperty("oss.bucket-name"), environment.getProperty("file.aliyunPath") + filename, invoicePdf.getInputStream());
|
||||
ossClient.shutdown();
|
||||
// 返回上传到阿里云中的文件的uri地址
|
||||
String fileAddress = "/" + environment.getProperty("file.aliyunPath") + filename;
|
||||
return AjaxResult.success(fileAddress);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给指定用户开发票,开票完成之后将开出的电子发票发送至用户的接收邮箱
|
||||
|
||||
@ -23,3 +23,17 @@ spring:
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
#oss默认配置
|
||||
oss:
|
||||
enabled: true
|
||||
name: qiniu
|
||||
tenant-mode: true
|
||||
endpoint: oss-accelerate.aliyuncs.com
|
||||
access-key: LTAI5tBWjnuQGxGicnThwMF1
|
||||
secret-key: b0WNtFYtWyTEkZzcr2WOAPoZg6w2Xu
|
||||
bucket-name: xhpc-bucket1
|
||||
|
||||
#文件路径
|
||||
file:
|
||||
aliyunPath: invoicePdf/
|
||||
Loading…
x
Reference in New Issue
Block a user