| | |
| | | package com.java110.core.client; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.aliyun.oss.OSSClient; |
| | | import com.java110.utils.cache.MappingCache; |
| | | import com.java110.core.factory.LogFactory; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import com.java110.utils.util.Base64Convert; |
| | | import com.java110.utils.util.DateUtil; |
| | | import com.java110.utils.util.OSSUtil; |
| | | import org.slf4j.Logger; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | |
| | | OSSClient ossClient = null; |
| | | ByteArrayInputStream is = null; |
| | | String urlPath = ""; |
| | | String resMsg = "上传成功"; |
| | | try { |
| | | ossClient = OSSUtil.getOSSClient(); |
| | | fileName = UUID.randomUUID().toString(); |
| | |
| | | byte[] context = Base64Convert.base64ToByte(imageBase64); |
| | | is = new ByteArrayInputStream(context); |
| | | |
| | | OSSUtil.uploadByInputStream(ossClient, is, ftpPath + urlPath); |
| | | OSSUtil.uploadByInputStream(ossClient, is, ftpPath + urlPath); |
| | | } catch (Exception e) { |
| | | logger.error("上传文件失败", e); |
| | | throw new IllegalArgumentException("上传文件失败"); |
| | | resMsg = e.getMessage()+e.getLocalizedMessage(); |
| | | throw new IllegalArgumentException("上传文件失败" + e.getMessage()); |
| | | } finally { |
| | | if (is != null) { |
| | | try { |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | LogFactory.saveOutLog("OSS", "文件", new ResponseEntity(resMsg, HttpStatus.OK)); |
| | | |
| | | } |
| | | return urlPath; |
| | | } |
| | |
| | | return fileName; |
| | | } |
| | | |
| | | public String upload(InputStream inputStream, String ftpPath) { |
| | | public String upload(InputStream inputStream, String ftpPath) { |
| | | OSSClient ossClient = null; |
| | | try { |
| | | ossClient = OSSUtil.getOSSClient(); |
| | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public InputStream download(String fileName) { |
| | | OSSClient ossClient = null; |
| | | InputStream is = null; |
| | | try { |
| | | ossClient = OSSUtil.getOSSClient(); |
| | | is = OSSUtil.getInputStreamByOSS(ossClient, fileName); |
| | | if (null == is) { |
| | | throw new FileNotFoundException(fileName); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("ftp通过文件名称获取远程文件流", e); |
| | | } |
| | | return is; |
| | | } |
| | | |
| | | } |