예제 #1
0
파일: UploadToS3.java 프로젝트: jq/zhong
  public static boolean upload(MusicInfo music) {
    String key = "";
    try {
      // upload  mp3 ring
      key = music.getUUID() + music.getRingName();
      File file = new File(Consts.NEW_DOWNLOAD_DIR + music.getRingName());
      s3.putObject(new PutObjectRequest(Consts.AMAZON_RING_BUCKET, key, file)); // upload ring
      s3.setObjectAcl(
          Consts.AMAZON_RING_BUCKET, key, CannedAccessControlList.PublicRead); // set access

      // upload m4r ring
      //			String m4r = music.getRingName().replace(".mp3", ".m4r");
      //			key = music.getUUID() + m4r;
      //			file = new File(Consts.NEW_DOWNLOAD_DIR+m4r);
      //			s3.putObject(new PutObjectRequest(Consts.AMAZON_M4R_BUCKET, key, file));      			//
      // upload ring
      //			s3.setObjectAcl(Consts.AMAZON_M4R_BUCKET, key, CannedAccessControlList.PublicRead);		//
      // set access

      // upload image
      key = music.getUUID() + music.getImageName();
      file = new File(Consts.NEW_DOWNLOAD_DIR + music.getImageName());
      s3.putObject(new PutObjectRequest(Consts.AMAZON_IMAGE_BUCKET, key, file)); // upload image
      s3.setObjectAcl(
          Consts.AMAZON_IMAGE_BUCKET, key, CannedAccessControlList.PublicRead); // set access

      return true;
    } catch (Exception e) {
      System.out.println("upload to S3 err");
      e.printStackTrace();
      return false;
    }
  }
예제 #2
0
  // 将文件f放到bucket中,名为name; 权限为公共读写。
  public static void putObjectInBucket(Bucket bucket, String name, File f) {

    conn.putObject(bucket.getName(), name, f);
    conn.setObjectAcl(bucket.getName(), name, CannedAccessControlList.PublicReadWrite);
  }