forked from kidgrow-microservices-platform

克 刘
2020-04-16 1eaf1fbc87b06d8f90ed8719d1ed298eac9f881a
kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/config/AliyunOSSAutoConfigure.java
@@ -1,6 +1,8 @@
package com.kidgrow.filecenter.config;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.kidgrow.common.utils.DateUtil;
import com.kidgrow.filecenter.model.FileInfo;
import com.kidgrow.filecenter.properties.FileServerProperties;
import com.kidgrow.filecenter.service.impl.AbstractIFileService;
@@ -8,10 +10,10 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.aliyun.oss.OSSClient;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
@@ -51,12 +53,14 @@
        @Override
        protected void uploadFile(MultipartFile file, FileInfo fileInfo) throws Exception {
            ossClient.putObject(fileProperties.getOss().getBucketName(), fileInfo.getName(), file.getInputStream());
            fileInfo.setUrl(fileProperties.getOss().getDomain() + "/" + fileInfo.getName());
            String folderByDate =DateUtil.formatDate(new Date());
            ossClient.putObject(fileProperties.getOss().getBucketName(), fileProperties.getOss().getFolder()+ folderByDate+"/"+fileInfo.getName(), file.getInputStream());
            fileInfo.setUrl(fileProperties.getOss().getDomain() + fileProperties.getOss().getFolder()+ folderByDate+"/" + fileInfo.getName());
        }
        @Override
        protected boolean deleteFile(FileInfo fileInfo) {
            ossClient.deleteObject(fileProperties.getOss().getBucketName(), fileInfo.getName());
            return true;
        }