示例#1
0
 /**
  * 七牛上传
  *
  * @param bytes
  * @param key
  * @return 下载链接
  * @throws QiniuException
  */
 public String upload(byte[] bytes, String key) throws QiniuException {
   String token = this.getToken();
   UploadManager uploadManager = new UploadManager();
   Response res = uploadManager.put(bytes, key, token);
   if (res.isOK()) {
     // 获取私有下载 URL
     // String downloadUrl = auth.privateDownloadUrl("http://" + domain + "/" + fileName);
     return domain + "/" + key;
   }
   return null;
 }
示例#2
0
  public static void upLoadFile(byte[] file, String key) {
    try {

      Response res = uploadManager.put(file, key, auth.uploadToken("xizhimojie"));
      // log.info(res);
      // log.info(res.bodyString());
      // Ret ret = res.jsonToObject(Ret.class);
      if (res.isOK()) {
        log.info(key + "上传成功!");
      } else {
        log.error(key + "上传失败!");
      }
    } catch (QiniuException e) {
      Response r = e.response;
      // 请求失败时简单状态信息
      log.error(r.toString());
      try {
        // 响应的文本信息
        log.error(r.bodyString());
      } catch (QiniuException e1) {
        // ignore
      }
    }
  }