FDFS的文件上傳和下載測試代碼

**

fdfs的文件上傳和下載測試代碼

**

@SpringBootTest
@RunWith(SpringRunner.class)
public class Fdfstest  {

@Autowired
private FastFileStorageClient storageClient;

    /**
     *  文件上傳
     */
@Test
public void Upload() throws FileNotFoundException {

    File file = new File("C:\\Users\\chenda\\Desktop\\圖片\\1.jpg");
    HashSet mataDataHashMap = new HashSet<MataData>();
    StorePath jpg = storageClient.uploadFile(new FileInputStream(file), file.length(), "JPG", mataDataHashMap);
    System.out.println(jpg.getGroup()+jpg.getPath());
}
/**
 * 文件下載
 */
@Test
public void download () throws IOException {
    // 下載的內容字節數組
    byte[] bytes = storageClient.downloadFile("group1", "M00/00/00/wKhqgVugw_GAYHamAAD3zaNpXcw574.JPG", new DownloadByteArray());
    FileOutputStream outputStream = new FileOutputStream("D:\\圖片\\da.jpg");
    outputStream.write(bytes);
    outputStream.close();
}

/**
 * 文件刪除
 */
@Test
public void testDelete(){
    storageClient.deleteFile("group1", "M00/00/00/wKhqgVugw_GAYHamAAD3zaNpXcw574.JPG");
}

/**
 *  上傳文件縮略圖
 */
@Test
public void testOther() throws FileNotFoundException {
    //上傳縮略圖的方法
    File file = new File("C:\\Users\\chenda\\Desktop\\圖片\\1.jpg");
    HashSet<MataData> metadata = new HashSet<MataData>();
    metadata.add(new MataData("width","1024"));
    StorePath storePath = storageClient.uploadImageAndCrtThumbImage(new FileInputStream(file), file.length(), "JPG", metadata);
    System.out.println(storePath.getFullPath());
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章