Search in sources :

Example 6 with VirtualFile

use of com.zhouzifei.tool.dto.VirtualFile in project simpleFS by shengdingbox.

the class XMLYApiClient method main.

public static void main(String[] args) {
    final FileProperties fileProperties = new FileProperties();
    fileProperties.getXmly().setCookies("Hm_lvt_4a7d8ec50cfd6af753c4f8aee3425070=1639114684; login_type=password_mobile; _xmLog=h5&9ea2efdf-7a5a-4f8d-8269-d9934707ef09&2.4.7-alpha.3; xm-page-viewid=ximalaya-web; x_xmly_traffic=utm_source%253A%2526utm_medium%253A%2526utm_campaign%253A%2526utm_content%253A%2526utm_term%253A%2526utm_from%253A; fds_otp=6230401576727727914; 1&remember_me=y; 1&_token=296993092&6B46C2A0340N0CBC4A6620979932BB1AF9474CD57A95BFBAEA25D9FDEE7710FBF352868FED80140M28D23A81E28D8FF_; 1_l_flag=296993092&6B46C2A0340N0CBC4A6620979932BB1AF9474CD57A95BFBAEA25D9FDEE7710FBF352868FED80140M28D23A81E28D8FF__2021-12-1015:49:16; Hm_lpvt_4a7d8ec50cfd6af753c4f8aee3425070=1639122558\n" + "origin: https://www.ximalaya.com");
    final XMLYApiClient init = new XMLYApiClient(fileProperties);
    final VirtualFile virtualFile = init.uploadFile(new File("/Users/Dabao/Downloads/qrcode_for_gh_da74abc7de78_258.jpg"));
    System.out.println(virtualFile);
// final String s1 = "username=17600004572&password=zhoudabao521.";
// final String s = HttpUtils.DataPost(requestUrl + "/token", s1);
// final JSONObject jsonObject = JSONObject.parseObject(s);
}
Also used : VirtualFile(com.zhouzifei.tool.dto.VirtualFile) XmlyFileProperties(com.zhouzifei.tool.config.XmlyFileProperties) FileProperties(com.zhouzifei.tool.config.FileProperties) VirtualFile(com.zhouzifei.tool.dto.VirtualFile) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 7 with VirtualFile

use of com.zhouzifei.tool.dto.VirtualFile in project simpleFS by shengdingbox.

the class AliyunOssApiClient method fileList.

@Override
public List<VirtualFile> fileList(FileListRequesr fileListRequesr) {
    this.check();
    // 设置最大个数。
    final int maxKeys = 200;
    String nextContinuationToken = null;
    ListObjectsV2Result result = null;
    // 指定前缀,例如exampledir/object。
    final String keyPrefix = fileListRequesr.getPrefix();
    List<VirtualFile> virtualFiles = new ArrayList<>();
    // 指定返回结果使用URL编码,则您需要对结果中的prefix、delemiter、startAfter、key和commonPrefix进行URL解码。
    do {
        ListObjectsV2Request listObjectsV2Request = new ListObjectsV2Request(bucketName).withMaxKeys(maxKeys);
        listObjectsV2Request.setPrefix(keyPrefix);
        listObjectsV2Request.setEncodingType("url");
        listObjectsV2Request.setContinuationToken(nextContinuationToken);
        result = client.listObjectsV2(listObjectsV2Request);
        // 文件名称解码。
        for (OSSObjectSummary s : result.getObjectSummaries()) {
            String decodedKey = null;
            try {
                decodedKey = URLDecoder.decode(s.getKey(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            assert decodedKey != null;
            if (decodedKey.contains("/")) {
                final String[] split = decodedKey.split("");
                this.newFileName = split[split.length - 1];
            } else {
                this.newFileName = decodedKey;
            }
            VirtualFile virtualFile = VirtualFile.builder().originalFileName(this.newFileName).suffix(this.suffix).uploadStartTime(s.getLastModified()).uploadEndTime(s.getLastModified()).filePath(decodedKey).size(s.getSize()).fileHash(s.getETag()).fullFilePath(this.newFileUrl + decodedKey).build();
            virtualFiles.add(virtualFile);
        }
        nextContinuationToken = result.getNextContinuationToken();
    } while (result.isTruncated());
    // 关闭OSSClient。
    client.shutdown();
    return virtualFiles;
}
Also used : VirtualFile(com.zhouzifei.tool.dto.VirtualFile) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

VirtualFile (com.zhouzifei.tool.dto.VirtualFile)7 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ArrayList (java.util.ArrayList)3 FileProperties (com.zhouzifei.tool.config.FileProperties)2 File (java.io.File)2 Date (java.util.Date)2 CosClientException (com.qcloud.cos.exception.CosClientException)1 AwsFileProperties (com.zhouzifei.tool.config.AwsFileProperties)1 XmlyFileProperties (com.zhouzifei.tool.config.XmlyFileProperties)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1