OSS上传txt文件乱码问题
设置文件的元信息,将文件的Content-type设置为:txt/plain;charset=utf-8就行了
public static void main(String[] args) throws FileNotFoundException {
String endpoint = "";
String accessKeyId = "";
String secretAccessKey = "";
String bucketName = "";
String filePath = "";
String key = "";
InputStream inputStream = new FileInputStream(filePath);
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, secretAccessKey);
ObjectMetadata objectMetadata = new ObjectMetadata();
// 设置content type
objectMetadata.setContentType("txt/plain;charset=utf-8");
PutObjectResult result = ossClient.putObject(bucketName, key, inputStream, objectMetadata);
// 访问路径
System.out.println("https://" + bucketName + "." + endpoint + "/" + key);
}
参考链接:
https://developer.aliyun.com/ask/115900?spm=a2c6h.13159736
https://blog.csdn.net/whereismatrix/article/details/45620159