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

org.zodiac.boot.file.LocalFile Maven / Gradle / Ivy

The newest version!
package org.zodiac.boot.file;

import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zodiac.boot.config.PlatformUploadFileInfo;

/**
 * 上传文件封装。
 *
 */
public abstract class LocalFile {

    protected final Logger log = LoggerFactory.getLogger(getClass());

    /**
     * 上传文件在附件表中的id
     */
    private Object fileId;

    /**
     * 文件外网地址
     */
    private String domain;

    /**
     * 上传分类文件夹
     */
    private String dir;

    /**
     * 文件配置。
     */
    private final PlatformUploadFileInfo platformFileInfo;

    public LocalFile(PlatformUploadFileInfo platformFileInfo, String dir) {
        this.platformFileInfo = Objects.requireNonNull(platformFileInfo);
        this.dir = dir;
        this.domain = getPlatformFileInfo().getUploadDomain();
    }

    public Object getFileId() {
        return fileId;
    }

    public void setFileId(Object fileId) {
        this.fileId = fileId;
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getDir() {
        return dir;
    }

    public void setDir(String dir) {
        this.dir = dir;
    }

    /**
     * 图片上传。
     */
    public void transfer() {
        transfer(getPlatformFileInfo().isCompressImage());
    }

    /**
     * 图片上传。
     *
     * @param compress 是否压缩
     */
    public void transfer(boolean compress) {
        FileProxy fileFactory = FileProxyManager.me().getDefaultFileProxyFactory();
        this.transfer(fileFactory, compress);
    }

    /**
     * 图片上传。
     *
     * @param fileFactory 文件上传工厂类
     * @param compress 是否压缩
     */
    public abstract void transfer(FileProxy fileFactory, boolean compress);

    public abstract String getFileName();

    public abstract String getOriginalFileName();

    public abstract String getUploadPath();

    protected final PlatformUploadFileInfo getPlatformFileInfo() {
        return platformFileInfo;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy