Search in sources :

Example 1 with StorePath

use of com.github.tobato.fastdfs.domain.fdfs.StorePath in project note by kebukeYi.

the class FastDFSClient method uploadImageAndCrtThumbImage.

/**
 * @param file 图片对象
 * @return 返回图片地址
 * @author qbanxiaoli
 * @description 上传缩略图
 */
public static String uploadImageAndCrtThumbImage(File file) {
    try {
        FileInputStream inputStream = new FileInputStream(file);
        StorePath storePath = fastFileStorageClient.uploadImageAndCrtThumbImage(inputStream, file.length(), FilenameUtils.getExtension(file.getName()), null);
        return storePath.getFullPath();
    } catch (Exception e) {
        log.error(e.getMessage());
        return null;
    }
}
Also used : StorePath(com.github.tobato.fastdfs.domain.fdfs.StorePath)

Example 2 with StorePath

use of com.github.tobato.fastdfs.domain.fdfs.StorePath in project note by kebukeYi.

the class FastDFSClient method uploadFile.

/**
 * @param bytes         byte数组
 * @param fileExtension 文件扩展名
 * @return 返回文件地址
 * @author qbanxiaoli
 * @description 将byte数组生成一个文件上传
 */
public static String uploadFile(byte[] bytes, String fileExtension) {
    ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
    StorePath storePath = fastFileStorageClient.uploadFile(stream, bytes.length, fileExtension, null);
    return storePath.getFullPath();
}
Also used : StorePath(com.github.tobato.fastdfs.domain.fdfs.StorePath)

Example 3 with StorePath

use of com.github.tobato.fastdfs.domain.fdfs.StorePath in project Spring-Cloud by zhao-staff-officer.

the class FastDFSClient method uploadFile.

/**
 * 将一段字符串生成一个文件上传
 * @param content 文件内容
 * @param fileExtension
 * @return
 */
public String uploadFile(String content, String fileExtension) {
    byte[] buff = content.getBytes(Charset.forName("UTF-8"));
    ByteArrayInputStream stream = new ByteArrayInputStream(buff);
    StorePath storePath = storageClient.uploadFile(stream, buff.length, fileExtension, null);
    return getResAccessUrl(storePath);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StorePath(com.github.tobato.fastdfs.domain.fdfs.StorePath)

Example 4 with StorePath

use of com.github.tobato.fastdfs.domain.fdfs.StorePath in project albedo by somowhere.

the class FastDfsFileChunkStrategyImpl method merge.

@Override
protected Result<File> merge(List<java.io.File> files, String path, String fileName, FileChunksMergeDto info) throws IOException {
    StorePath storePath = null;
    long start = System.currentTimeMillis();
    for (int i = 0; i < files.size(); i++) {
        java.io.File file = files.get(i);
        FileInputStream in = FileUtils.openInputStream(file);
        if (i == 0) {
            storePath = storageClient.uploadAppenderFile(null, in, file.length(), info.getExt());
        } else {
            storageClient.appendFile(storePath.getGroup(), storePath.getPath(), in, file.length());
        }
    }
    if (storePath == null) {
        return Result.buildFail("上传失败");
    }
    long end = System.currentTimeMillis();
    log.info("上传耗时={}", (end - start));
    String url = fileProperties.getFastDfs().getUrlPrefix() + storePath.getFullPath();
    File filePo = File.builder().url(url).bucket(storePath.getGroup()).path(storePath.getPath()).build();
    return Result.buildOkData(filePo);
}
Also used : File(com.albedo.java.modules.file.domain.File) FileInputStream(java.io.FileInputStream) StorePath(com.github.tobato.fastdfs.domain.fdfs.StorePath)

Example 5 with StorePath

use of com.github.tobato.fastdfs.domain.fdfs.StorePath in project oner365-cloud by xiaozhao32.

the class FileFdfsClient method uploadFile.

/**
 * 上传文件
 *
 * @param file 文件对象
 *
 * @return 文件访问地址
 */
@Override
public String uploadFile(MultipartFile file, String directory) {
    try (InputStream in = file.getInputStream()) {
        StorePath storePath = fastFileStorageClient.uploadFile(in, file.getSize(), getExtName(file.getOriginalFilename(), file.getContentType()), null);
        String url = getResAccessUrl(storePath);
        saveFileStorage(url, file.getOriginalFilename(), file.getSize());
        return url;
    } catch (IOException e) {
        logger.error("upload MultipartFile IOException:", e);
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) StorePath(com.github.tobato.fastdfs.domain.fdfs.StorePath)

Aggregations

StorePath (com.github.tobato.fastdfs.domain.fdfs.StorePath)12 FileInputStream (java.io.FileInputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 File (com.albedo.java.modules.file.domain.File)1 DownloadByteArray (com.github.tobato.fastdfs.domain.proto.storage.DownloadByteArray)1 FdfsUnsupportStorePathException (com.github.tobato.fastdfs.exception.FdfsUnsupportStorePathException)1 InputStream (java.io.InputStream)1