Пример #1
0
  /**
   * @param file 文件
   * @param fileName 文件名
   * @return 返回Null则为失败
   */
  public static String uploadFile(File file, String fileName) {
    FileInputStream fis = null;
    try {
      NameValuePair[] meta_list = null; // new NameValuePair[0];
      fis = new FileInputStream(file);
      byte[] file_buff = null;
      if (fis != null) {
        int len = fis.available();
        file_buff = new byte[len];
        fis.read(file_buff);
      }

      String fileid = storageClient1.upload_file1(file_buff, getFileExt(fileName), meta_list);
      return fileid;
    } catch (Exception ex) {
      logger.error(ex);
      return null;
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (IOException e) {
          logger.error(e);
        }
      }
    }
  }
Пример #2
0
 /**
  * 根据组名和远程文件名来删除一个文件
  *
  * @param groupName 例如 "group1" 如果不指定该值,默认为group1
  * @param fileName 例如"M00/00/00/wKgxgk5HbLvfP86RAAAAChd9X1Y736.jpg"
  * @return 0为成功,非0为失败,具体为错误代码
  */
 public static int deleteFile(String groupName, String fileName) {
   try {
     int result = storageClient1.delete_file(groupName == null ? "group1" : groupName, fileName);
     return result;
   } catch (Exception ex) {
     logger.error(ex);
     return 0;
   }
 }
Пример #3
0
 /**
  * 根据fileId来删除一个文件(我们现在用的就是这样的方式,上传文件时直接将fileId保存在了数据库中)
  *
  * @param fileId file_id源码中的解释file_id the file id(including group name and filename);例如
  *     group1/M00/00/00/ooYBAFM6MpmAHM91AAAEgdpiRC0012.xml
  * @return 0为成功,非0为失败,具体为错误代码
  */
 public static int deleteFile(String fileId) {
   try {
     int result = storageClient1.delete_file1(fileId);
     return result;
   } catch (Exception ex) {
     logger.error(ex);
     return 0;
   }
 }
Пример #4
0
 /**
  * 文件下载
  *
  * @param fileId
  * @return 返回一个流
  */
 public static InputStream downloadFile(String fileId) {
   try {
     byte[] bytes = storageClient1.download_file1(fileId);
     InputStream inputStream = new ByteArrayInputStream(bytes);
     return inputStream;
   } catch (Exception ex) {
     logger.error(ex);
     return null;
   }
 }
Пример #5
0
 /**
  * 上传文件方法
  *
  * @param fileContent 文件的内容,字节数组
  * @param extName 文件扩展名
  * @param metas 文件扩展信息
  * @return
  */
 public String uploadFile(byte[] fileContent, String extName, NameValuePair[] metas)
     throws Exception {
   String result = storageClient.upload_file1(fileContent, extName, metas);
   return result;
 }
Пример #6
0
 /**
  * 上传文件方法
  *
  * @param fileName 文件全路径
  * @param extName 文件扩展名,不包含(.)
  * @param metas 文件扩展信息
  * @return
  * @throws Exception
  */
 public String uploadFile(String fileName, String extName, NameValuePair[] metas)
     throws Exception {
   String result = storageClient.upload_appender_file1(fileName, extName, metas);
   return result;
 }