| | |
| | | import com.ruoyi.common.core.utils.uuid.IdUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.*; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStream; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author jqs34 |
| | |
| | | * @date 2023 2023/5/1 15:40 |
| | | */ |
| | | public class OBSUploadUtils { |
| | | |
| | | |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | String fileUrl = null; |
| | |
| | | OSS ossClient = createOss(); |
| | | PutObjectResult result = null; |
| | | try { |
| | | |
| | | String fileName = FileUploadUtils.extractFilename(file); |
| | | System.out.println(fileName + "开始上传"); |
| | | System.out.println(fileName + "开始上传" + new Date()); |
| | | String prefix = fileName.substring(fileName.lastIndexOf(".")); |
| | | String objectName = filePath + uuid + prefix; |
| | | InputStream inputStream = file.getInputStream(); |
| | |
| | | // 创建PutObject请求。 |
| | | result = ossClient.putObject(putObjectRequest); |
| | | // 如果上传成功,则返回200。 |
| | | System.out.println(fileName + "上传返回" + result.getResponse().getStatusCode()); |
| | | System.out.println(fileName + "上传返回"+ new Date() + result.getResponse().getStatusCode()); |
| | | inputStream.close(); |
| | | return result.getResponse().getUri(); |
| | | } catch (OSSException oe) { |
| | | System.out.println("Caught an OSSException, which means your request made it to OSS, " |
| | |
| | | PutObjectResult result = null; |
| | | try { |
| | | |
| | | System.out.println(fileName + "开始上传"); |
| | | System.out.println(fileName + "开始上传"+ new Date()); |
| | | String objectName = filePath + fileName + ".jpg"; |
| | | // 创建PutObjectRequest对象。 |
| | | PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream); |
| | |
| | | // 创建PutObject请求。 |
| | | result = ossClient.putObject(putObjectRequest); |
| | | // 如果上传成功,则返回200。 |
| | | System.out.println(fileName + "上传返回" + result.getResponse().getStatusCode()); |
| | | System.out.println(fileName + "上传返回"+ new Date() + result.getResponse().getStatusCode()); |
| | | return result.getResponse().getUri(); |
| | | } catch (OSSException oe) { |
| | | System.out.println("Caught an OSSException, which means your request made it to OSS, " |