资源简介
springboot 写的微信小程序后台上传 包含了文件上传 和下载 由于文件是在整个后台中拿出来的,所以返回参数 可以根据自己需求进行修改。文件主要是在微信小程序 生成录音文件 或选择文件时 调用 wx.upload 方法上传文件的后台支持。
![](http://www.nz998.com/pic/65152.jpg)
代码片段和文件信息
package hongbao.web.controller;
import hongbao.autoconfig.F4jProperties;
import hongbao.autoconfig.FileProperties;
import hongbao.common.FileTypeEnum;
import hongbao.controller.baseController;
import hongbao.entity.HongBaoFile;
import hongbao.file.FileStore;
import hongbao.model.JsonResult;
import hongbao.model.ResultUtil;
import hongbao.model.VoiceStoreDto;
import hongbao.service.FileServiceI;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
@CrossOrigin
@RestController
@RequestMapping(“/file“)
public class FileController extends baseController {
@Autowired
private FileServiceI fileService;
@RequestMapping(value = “/uploadPicFile“ method = {RequestMethod.POST})
public JsonResult filePicUpload(@RequestParam(value = “file“) MultipartFile file) throws IOException {
String path= “文件存储路径“;
String fileName=file.getOriginalFilename();
if (!file.isEmpty()) {
try {
File fileDir = new File(path);
if (!fileDir.exists()) {// 判断目录是否存在
fileDir.mkdirs();
//dir.mkdirs(); //多层目录需要调用mkdirs
}
byte[] fdate = file.getBytes();
FileOutputStream out = new FileOutputStream(path+fileName);
out.write(fdate);
out.close();
//保存文件
/*
这里写文件业务逻辑
*/
return ResultUtil.success(bFile);
} catch (IOException e) {
e.printStackTrace();
return ResultUtil.error(410 “操作失败“);
}
}else {
return ResultUtil.error(410 “文件不能为空“);
}
}
@RequestMapping(value = “/fileDownload“ method = RequestMethod.GET)
public void fileDownload(@RequestParam(value = “fileId“) String fileIdHttpServletResponse res) {
//获取文件
HongBaoFile bFile = fileService.selectById(fileId);
res.setHeader(“content-type“ “application/octet-stream“);
res.setContentType(“application/octet-stream“);
res.setHeader(“Content-Disposition“ “attachment;filename=“ + bFile.getFileName());
byte[] buff = new byte[1024];
BufferedInputStream bis = null;
OutputStream os = null;
try {
os = res.getOutputStream();
bis = new BufferedInputStream(new FileInputStream(new File(bFile.getFilePath()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3574 2018-02-13 20:34 FileController.java
相关资源
- springboot商城系统
- 基于springboot和vue 前后端分离后台管理
- springboot2.0+spring cloud+eureka(分布式项
- Vue + SpringBoot + MyBatis 音乐网站(源码
- springBoot项目的代码生成器
- Java SpringBoot 支付宝和微信支付整合
- 整合springboot+mvc+mybatis(通用mapper)
- Java+SpringBoot+MyBatis+Maven+MySQL实现的一个
- jasperreport-fonts-6.5.1.jar 中文
- JavaEE开发的颠覆者 Spring Boot实战源代
- SpringBoot+iReport打印单张和多张报表包
- lombok jar包
- Springboot实现语音识别听写
- springboot网上书城项目毕业设计程序
- 基于springboot电商订单管理毕业设计程
- springboot教学评价系统毕业设计程序
- springboot床上用品销售系统毕业设计程
- springboot权限控制系统
- springboot家政服务平台毕业设计程序
- springboot校园招聘系统毕业设计程序
- [www.java1234.com]Springboot打造企业级进销
- Java框架springBoot企业级进销存ERP系统源
- springboot+JPA+JSP实现登录功能
- springboot+memcached+mybatis+shiro+webservice聚
- 2019JAVA BAT 面试宝典 springboot springm
- SpringBoot考试系统.rar
- SpringBoot+Echarts
- ssm+mysql+springboot开发的后台管理系统
- java web springboot License生成器 (JAVA源码
- 风电系统物联网iot平台监控、报表、
评论
共有 条评论