update 图片上传

This commit is contained in:
2023-04-28 16:42:39 +08:00
parent 90b52079b3
commit b5f1d93359

View File

@@ -3,20 +3,27 @@ package com.jsowell.api.uniapp;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.annotation.Anonymous; import com.jsowell.common.annotation.Anonymous;
import com.jsowell.common.core.controller.BaseController; import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.enums.ykc.ReturnCodeEnum; import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException; import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse; import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.file.AliyunOssUploadUtils;
import com.jsowell.common.util.file.FileUtils;
import com.jsowell.pile.service.IOrderBasicInfoService; import com.jsowell.pile.service.IOrderBasicInfoService;
import com.jsowell.pile.vo.uniapp.PileConnectorVO; import com.jsowell.pile.vo.uniapp.PileConnectorVO;
import com.jsowell.service.PileService; import com.jsowell.service.PileService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@Anonymous @Anonymous
@RestController @RestController
@RequestMapping("/app-xcx-h5") @RequestMapping("/app-xcx-h5")
@@ -73,13 +80,26 @@ public class JumpController extends BaseController {
} }
/** /**
* 更新接口 * 上传到阿里云oss
* http://localhost:8080/app-xcx-h5/pile/updateOrderDetail * http://localhost:8080/app-xcx-h5/uploadOSS
* @param file
* @return
* @throws Exception
*/ */
@GetMapping("updateOrderDetail") @CrossOrigin
public RestApiResponse<?> updateOrderDetail() { @PostMapping("/uploadOSS")
orderBasicInfoService.updateElecAmount(); public AjaxResult uploadFileOSS(MultipartFile file) throws Exception {
return new RestApiResponse<>(); try {
String url = AliyunOssUploadUtils.uploadFile(file);
AjaxResult ajax = AjaxResult.success();
ajax.put("url", url);
ajax.put("fileName", FileUtils.getName(url));
ajax.put("newFileName", FileUtils.getName(url));
ajax.put("originalFilename", file.getOriginalFilename());
return ajax;
}catch (Exception e){
return AjaxResult.error(e.getMessage());
}
} }
} }