| | |
| | | |
| | | import com.stylefeng.guns.config.properties.GunsProperties; |
| | | import com.stylefeng.guns.core.base.controller.BaseController; |
| | | import com.stylefeng.guns.core.base.tips.SuccessTip; |
| | | import com.stylefeng.guns.core.common.exception.BizExceptionEnum; |
| | | import com.stylefeng.guns.core.exception.GunsException; |
| | | import com.stylefeng.guns.core.util.ObsUploadUtil; |
| | | import com.stylefeng.guns.modular.cloudPayment.example.MediaExample; |
| | | import com.stylefeng.guns.modular.system.model.TImgMid; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.system.service.ITImgMidService; |
| | | import com.stylefeng.guns.modular.system.util.OssUploadUtil; |
| | | import com.unionpay.upyzt.exception.UpyztException; |
| | | import com.unionpay.upyzt.resp.MediaResp; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | MultipartFile file = (MultipartFile) multipartRequest.getFile("myfile"); |
| | | if (file.getSize() != 0) { |
| | | ossUpload = OssUploadUtil.ossUpload(request, file); |
| | | String fileName = UUID.randomUUID().toString() + "." + ToolUtil.getFileSuffix(file.getOriginalFilename()); |
| | | try { |
| | | String fileSavePath = gunsProperties.getFileUploadPath() + "img\\"; |
| | | file.transferTo(new File(fileSavePath + fileName)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | ossUpload = gunsProperties.getPictureServerAddress() + "img/" + fileName; |
| | | |
| | | |
| | | // ossUpload = OssUploadUtil.ossUpload(request, file); |
| | | // ossUpload = ObsUploadUtil.obsUpload(super.getHttpServletRequest(), file); |
| | | m.put("imgUrl", ossUpload); |
| | | } |
| | |
| | | } |
| | | @Resource |
| | | private ITImgMidService itImgMidService; |
| | | |
| | | @RequestMapping("/image") |
| | | @ResponseBody |
| | | public Object image(@RequestPart("file") MultipartFile picture, HttpServletRequest request) { |
| | | try { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | MultipartFile file = (MultipartFile) picture; |
| | | String pictureName = OssUploadUtil.ossUpload(request, file); |
| | | System.out.println("mediaResp"); |
| | | MediaResp mediaResp = MediaExample.uploadImage(picture); |
| | | System.out.println("------"+mediaResp); |
| | | TImgMid tImgMid = new TImgMid(); |
| | | tImgMid.setMid(mediaResp.getMediaId()); |
| | | tImgMid.setUrl(pictureName); |
| | | itImgMidService.insert(tImgMid); |
| | | // String pictureName = ObsUploadUtil.obsUpload(super.getHttpServletRequest(), picture); |
| | | return pictureName; |
| | | } catch (UpyztException e){ |
| | | e.printStackTrace(); |
| | | return ERROR; |
| | | }catch (Exception e1) { |
| | | e1.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | |
| | | @RequestMapping("/image1") |
| | | @ResponseBody |
| | | public String image1(@RequestPart("file") MultipartFile picture, HttpServletRequest request) { |
| | | try { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | MultipartFile file = (MultipartFile) picture; |
| | | String pictureName = OssUploadUtil.ossUpload(request, file); |
| | | |
| | | String fileName = UUID.randomUUID().toString() + "." + ToolUtil.getFileSuffix(file.getOriginalFilename()); |
| | | try { |
| | | String fileSavePath = gunsProperties.getFileUploadPath() + "img\\"; |
| | | file.transferTo(new File(fileSavePath + fileName)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String pictureName = gunsProperties.getPictureServerAddress() + "img/" + fileName; |
| | | |
| | | // String pictureName = OssUploadUtil.ossUpload(request, file); |
| | | System.out.println("mediaResp"); |
| | | // MediaResp mediaResp = MediaExample.uploadImage(picture); |
| | | // System.out.println("------"+mediaResp); |
| | |
| | | @RequestMapping("/imageUp") |
| | | public String imageUp(@RequestPart("upfile") MultipartFile picture, HttpServletRequest request) { |
| | | String callback = request.getParameter("callback"); |
| | | String pictureName = UUID.randomUUID().toString() + ".jpg"; |
| | | try { |
| | | // 上传文件目录 |
| | | //String fileSavePath = gunsProperties.getFileUploadPath(); |
| | | //picture.transferTo(new File(fileSavePath + pictureName)); |
| | | // 文件全路径 |
| | | //pictureName = gunsProperties.getPictureServerAddress() + pictureName; |
| | | // pictureName = ObsUploadUtil.obsUpload(super.getHttpServletRequest(), picture); |
| | | pictureName = OssUploadUtil.ossUpload(super.getHttpServletRequest(), picture); |
| | | |
| | | String fileName = UUID.randomUUID().toString() + "." + ToolUtil.getFileSuffix(picture.getOriginalFilename()); |
| | | try { |
| | | String fileSavePath = gunsProperties.getFileUploadPath() + "img\\"; |
| | | picture.transferTo(new File(fileSavePath + fileName)); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String pictureName = gunsProperties.getPictureServerAddress() + "img/" + fileName; |
| | | // pictureName = OssUploadUtil.ossUpload(super.getHttpServletRequest(), picture); |
| | | |
| | | String result = "{'original': '" + picture.getOriginalFilename() + "', 'state': 'SUCCESS', 'url': '" + pictureName + "'}"; |
| | | if (callback == null) { |
| | | return result; |