/**
  * 删除文件
  *
  * @param fileName
  */
 @Override
 public void deleteFile(String fileName) {
   if (BAIDU_BCS == null) {
     BAIDU_BCS = new BaiduBCS(new BCSCredentials(AK, SK), HOST);
   }
   BAIDU_BCS.deleteObject(BUCKET, fileName);
 }
 /**
  * 获取fileName的地址
  *
  * @param fileName
  * @return
  */
 @Override
 public String getUrl(String fileName) {
   if (BAIDU_BCS == null) {
     BAIDU_BCS = new BaiduBCS(new BCSCredentials(AK, SK), HOST);
   }
   GenerateUrlRequest generateUrlRequest =
       new GenerateUrlRequest(HttpMethodName.GET, BUCKET, fileName);
   return BAIDU_BCS.generateUrl(generateUrlRequest);
 }
Ejemplo n.º 3
0
 private boolean deletePhoto(String path) {
   boolean flag = false;
   try {
     log.debug(
         "===========" + UserController.class.getName() + " :delete photo begin ===========");
     BCSCredentials credentials =
         new BCSCredentials(FinalVariable.BAE_USERNAME, FinalVariable.BAE_PASSWORD);
     BaiduBCS baiduBCS = new BaiduBCS(credentials, FinalVariable.BCSHOST);
     DeleteObjectRequest objectRequest = new DeleteObjectRequest(FinalVariable.BUCKET, path);
     baiduBCS.deleteObject(objectRequest);
     log.debug(
         "===========" + UserController.class.getName() + " :delete photo succeed ===========");
     flag = true;
   } catch (Exception e) {
     log.debug(
         "===========" + UserController.class.getName() + " :" + e.getMessage() + "===========");
     flag = false;
   }
   return flag;
 }
 /**
  * 从云端下载文件
  *
  * @param fileName
  * @return
  */
 @Override
 public InputStream download(String fileName) {
   if (BAIDU_BCS == null) {
     BAIDU_BCS = new BaiduBCS(new BCSCredentials(AK, SK), HOST);
   }
   GetObjectRequest request = new GetObjectRequest(BUCKET, fileName);
   BaiduBCSResponse<DownloadObject> response = BAIDU_BCS.getObject(request);
   DownloadObject downloadObject = response.getResult();
   InputStream result = null;
   if (downloadObject != null) {
     result = downloadObject.getContent();
   }
   return result;
 }
  /**
   * 上传文件到云端
   *
   * @param fileName
   * @param contents
   * @throws IOException
   */
  @Override
  public String upload(String fileName, byte[] contents) {
    if (BAIDU_BCS == null) {
      BAIDU_BCS = new BaiduBCS(new BCSCredentials(AK, SK), HOST);
    }
    ObjectMetadata objectMetadata = new ObjectMetadata();
    objectMetadata.setContentEncoding("utf-8");
    objectMetadata.setContentLength(contents.length);

    PutObjectRequest request =
        new PutObjectRequest(BUCKET, fileName, new ByteArrayInputStream(contents), objectMetadata);
    BAIDU_BCS.putObject(request);
    return getUrl(fileName);
  }
Ejemplo n.º 6
0
 private static void getObjectWithDestFile(BaiduBCS baiduBCS, String object, File destFile) {
   GetObjectRequest getObjectRequest =
       new GetObjectRequest(AppAutoConstants.Baidu_BCS.bucket, object);
   baiduBCS.getObject(getObjectRequest, destFile);
 }