查询景区信息和机位接口实现

This commit is contained in:
longbinbin
2024-12-06 10:55:49 +08:00
parent 6bfd3d2f45
commit 2b919a3c9f
14 changed files with 287 additions and 99 deletions

View File

@ -20,8 +20,14 @@ public class OssUtil {
@Autowired
private OssConfig ossConfig;
/**
* 上传文件到oss
* @param inputStream 文件数据流
* @param filename 文件全路径名称
* @return
*/
public String uploadFile(InputStream inputStream, String filename) {
String uploadFileName = ossConfig.getObjectName() + System.currentTimeMillis() + filename.substring(filename.lastIndexOf("."));
String uploadFileName = ossConfig.getObjectName() + filename;
OSS ossClient = new OSSClientBuilder().build(ossConfig.getEndPoint(), ossConfig.getAccessKeyId(), ossConfig.getAccessKeySecret());
try {
PutObjectRequest putObjectRequest = new PutObjectRequest(ossConfig.getBucketName(), uploadFileName, inputStream);

View File

@ -1,87 +0,0 @@
package com.ycwl.basic.utils.oss;
import cn.hutool.core.util.StrUtil;
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.PutObjectRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.InputStream;
/**
* @Author:longbinbin
* @Date:2024/11/6 10:12
*
* 参考文档:https://help.aliyun.com/zh/oss/getting-started/sdk-quick-start?spm=a2c4g.11186623.help-menu-31815.d_1_5.7065a784pbkMck
*/
@Slf4j
@Component
public class OssUtil {
@Value("${aliyun.oss.endpoint}")
private String endPoint;
@Value("${aliyun.oss.accessKeyId}")
private String accessKeyId;
@Value("${aliyun.oss.accessKeySecret}")
private String accessKeySecret;
@Value("${aliyun.oss.bucketName}")
private String bucketName;
@Value("${aliyun.oss.url}")
private String url;
/**
* 上传文件到oss
* @param inputStream 文件数据输入流
* @param filepath 文件路径
* @param filename 文件名
* @return
*/
public String uploadFile(InputStream inputStream, String filepath, String filename) {
String uploadFileName ;
if (StrUtil.isNotBlank(filepath)) {
uploadFileName = filepath+filename;
}else {
uploadFileName=filename;
}
OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
try {
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName,uploadFileName, inputStream);
ossClient.putObject(putObjectRequest);
log.info("人脸照片上传成功");
String fileUrl = url+uploadFileName;
return fileUrl;
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
return "上传失败";
}
/**
* 删除文件
* @param filePath 文件路径
* @return
*/
public Boolean deleteFile(String filePath) {
return null;
}
}