
package com.cusc.nirvana.user.rnr;

import cn.hutool.core.codec.Base64Encoder;
import com.alibaba.excel.util.IoUtils;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import com.cusc.nirvana.user.rnr.fp.common.util.DateUtil;
import com.cusc.nirvana.user.rnr.fp.util.ImgUtil;
import com.cusc.nirvana.user.util.CuscStringUtils;
import com.cusc.nirvana.user.util.DateUtils;

import javax.imageio.ImageIO;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays;
import java.util.Date;


/**
 * @author stayAnd
 * @date 2022/6/22
 */

public class OssTest {

	static String endpoint = "http://oss-cn-nanjing.aliyuncs.com";
	static String accessKeyId = "LTAI5tAF2jKTVDkv5dtqNatu";
	static String accessKeySecret = "wrioJnGZnCKH5EakLbsCGyrxXjQAcz";
	static String bucketName = "local-rnr";


	public static void main(String[] args)  throws Exception{
		//FileInputStream fileInputStream = new FileInputStream("/Users/stayand/Desktop/WechatIMG99.png");
		//String s = upLoadFile(fileInputStream);

		//String base64 = downLoadFileBase64(s);

		//System.out.println(base64);

		//f5a6f26f129e4ac8914bca267cb08207.png

		String url = getUrl("template/个人授权委托书.docx");
		System.out.println(url);
	}




	public static  String upLoadFile(InputStream inputStream){
		// 创建OSSClient实例。
		OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

		String fileId = CuscStringUtils.generateUuid() + ".png";

		PutObjectRequest request = new PutObjectRequest(bucketName,fileId,inputStream);
		//request.setProcess();

		PutObjectResult putObjectResult = ossClient.putObject(request);

		ossClient.shutdown();

		return fileId;
	}


	public static String getUrl(String ossFileName){
		// 创建OSSClient实例。
		OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
		Date date = new Date(System.currentTimeMillis() +(3600L * 1000) *2);
		URL url = ossClient.generatePresignedUrl(bucketName, ossFileName,date );
		return url.toString();
	}


}

