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;
|
}
|
}
|
|
|
}
|