| | |
| | | package com.kidgrow.filecenter.service.impl; |
| | | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import com.aliyun.oss.model.ObjectMetadata; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.kidgrow.common.constant.CommonConstant; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import net.coobird.thumbnailator.Thumbnails; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import sun.misc.BASE64Decoder; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStream; |
| | | import java.io.*; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | |
| | | return fileInfo; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public FileInfo baseUplaod(String file, String imgType) { |
| | | if(file==null||"".equals(file.trim())){ |
| | | return null; |
| | | } |
| | | String name=file.split(",")[0]; |
| | | file = file.split(",")[1]; |
| | | BASE64Decoder decoder = new BASE64Decoder(); |
| | | try { |
| | | byte[] bytes = decoder.decodeBuffer(file); |
| | | ObjectMetadata objectMeta = new ObjectMetadata(); |
| | | objectMeta.setContentLength(file.length()); |
| | | //将字节码转换成流 |
| | | InputStream input = new ByteArrayInputStream(bytes); |
| | | String fileName= UUID.randomUUID().toString().replaceAll("-",""); |
| | | //image/jpeg;base64 |
| | | String newFileName=fileName+"."+name.substring(name.lastIndexOf("/")+1,name.lastIndexOf(";")); |
| | | FileInfo newfileInfo=new FileInfo(); |
| | | newfileInfo.setName(newFileName); |
| | | newfileInfo.setId(IdUtil.fastSimpleUUID()); |
| | | newfileInfo.setSize(file.length()); |
| | | newfileInfo.setIsImg(true); |
| | | newfileInfo.setContentType("image/jpeg"); |
| | | newfileInfo.setSource("aliyun"); |
| | | newfileInfo.setImgType(imgType); |
| | | newfileInfo.setCreateTime(new Date()); |
| | | this.fileUpLoadOss(newfileInfo,"HospitalLogo/"+newFileName,input); |
| | | input.close(); |
| | | baseMapper.insert(newfileInfo); |
| | | return newfileInfo; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | |