最后
这份文档从构建一个键值数据库的关键架构入手,不仅带你建立起全局观,还帮你迅速抓住核心主线。除此之外,还会具体讲解数据结构、线程模型、网络框架、持久化、主从同步和切片集群等,帮你搞懂底层原理。相信这对于所有层次的Redis使用者都是一份非常完美的教程了。
整理不易,觉得有帮助的朋友可以帮忙点赞分享支持一下小编~
你的支持,我的动力;祝各位前程似锦,offer不断!!!
*/
public String uploadImage(MultipartFile file) throws Exception {
InputStream in = file.getInputStream();
String fileOriginalFilename = file.getOriginalFilename();
String fileName = fileOriginalFilename.split(“/”)[1];
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(in.available());
metadata.setCacheControl(“no-cache”);
metadata.setHeader(“Access-Control-Allow-Origin”, “*”);
metadata.setHeader(“Access-Control-Allow-Methods”, “POST GET HEAD PUT DELETE”);
metadata.setHeader(“Access-Control-Max-Age”, “3600”);
metadata.setHeader(“Pragma”, “no-cache”);
metadata.setContentEncoding(“utf-8”);
metadata.setContentType(fileName);
OSS oss = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
oss.putObject(bucket, fileDir + fileName, in, metadata);
oss.shutdown();
in.close();
return “https://” + bucket + “.” + endPoint + “/” + fileDir + fileName;
}
老样子,写完测试
OK!!!
Oss utils
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.ObjectMetadata;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.*;
/**
-
@author dugt1998@163.com
-
@date 2020/11/21 9:13
*/
@Component
public class OSSUtils {
private static final String END_POINT = “oss-cn-qingdao.aliyuncs.com”;
private static final String ACCESS_KEY_ID = “”;
private static final String ACCESS_KEY_SECRET = “”;
private static final String BUCKET = “”;
private static final String FILE_DIR = “test/”;
/**
-
上传文件
-
dugt1998@163.com
*/
public String uploadImage(MultipartFile file) throws Exception {
InputStream in = file.getInputStream();
String fileName = file.getOriginalFilename();
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(in.available());
metadata.setCacheControl(“no-cache”);
metadata.setHeader(“Access-Control-Allow-Origin”, “*”);
metadata.setHeader(“Access-Control-Allow-Methods”, “POST GET HEAD PUT DELETE”);
metadata.setHeader(“Access-Control-Max-Age”, “3600”);
metadata.setHeader(“Pragma”, “no-cache”);
metadata.setContentEncoding(“utf-8”);
metadata.setContentType(getContentType(fileName));
OSS oss = new OSSClientBuilder().build(END_POINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
oss.putObject(BUCKET, FILE_DIR + fileName, in, metadata);
oss.shutdown();
in.close();
return “https://” + BUCKET + “.” + END_POINT + “/” + FILE_DIR + fileName;
}
/**
-
根据图片名 判断oss是否存在图片
-
@return
*/
public boolean existsImg(String imgName) {
OSS oss = new OSSClientBuilder().build(END_POINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
String ossFileName = FILE_DIR + imgName;
最后
-1714839368386)]