zainali5120
2020-09-25 286ea89f5f6cade73276f865effa5dcd2b19406d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.xcong.excoin.utils;
 
import com.aliyun.oss.OSS;
import lombok.extern.slf4j.Slf4j;
import sun.misc.BASE64Decoder;
 
import java.io.ByteArrayInputStream;
 
/**
 * @author wzy
 * @date 2020-05-22
 **/
@Slf4j
public class OssUtils {
 
    private static final OSS OSS_CLIENT = (OSS) SpringContextHolder.getBean("ossClient");
 
    public static boolean uploadFileWithBase64(String base64, String pathName) {
        ByteArrayInputStream stream = null;
        try {
            BASE64Decoder decoder = new BASE64Decoder();
            byte[] bytes = decoder.decodeBuffer(base64);
            stream = new ByteArrayInputStream(bytes);
            OSS_CLIENT.putObject("excoin", pathName, stream);
            return true;
        } catch (Exception e) {
            log.error("#上传失败:{}#", e);
            return false;
        }
    }
 
 
}