All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zcj.ext.amazon.s3.AmazonS3Conver Maven / Gradle / Ivy

package com.zcj.ext.amazon.s3;

import com.zcj.util.UtilString;

public class AmazonS3Conver {

    public static final String ID_PREFIX = "AMAZONS3";
    public static final String ID_SPLIT = "###";

    // 生成文件ID,用于存储到数据库
    public static String initFileId(String bucket, String objectName) {
        return ID_PREFIX + ID_SPLIT + bucket + ID_SPLIT + objectName;
    }

    // 根据 文件ID 获取 bucket 和 object
    public static String[] toObjectInfo(String fileId) {
        String[] result = new String[2];
        if (UtilString.isNotBlank(fileId) && fileId.startsWith(AmazonS3Conver.ID_PREFIX)) {
            String[] fileInfo = fileId.split(ID_SPLIT);
            if (fileInfo.length == 3 && ID_PREFIX.equals(fileInfo[0])) {
                result[0] = fileInfo[1];
                result[1] = fileInfo[2];
            }
        }
        return result;
    }

    // 获取临时访问地址
    public static String initTempUrl(AmazonS3Util amazonS3Util, String fileId) {
        if (amazonS3Util == null || UtilString.isBlank(fileId)) {
            return null;
        }
        String[] fileInfo = toObjectInfo(fileId);
        return amazonS3Util.presignedGetObject(fileInfo[0], fileInfo[1]);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy