S3Service s3Service = new RestS3Service(awsCredentials); String key = formatLatLon(x, y) + ".tiff"; S3Object object = s3Service.getObject(awsBucketName, key);
S3Service service = new RestS3Service(myCredentials); objects = service.listObjects(bucketName ,directoryPathRelativeToBucket, null); log.info("got bucket listing for bucket[" + bucketName + "]"); } catch (S3ServiceException e) { log.error("Failed to get or object listing for bucket[" + bucketName + "] due to exception:", e); } for (org.jets3t.service.model.S3Object s3Object : objects) { if (s3Object.getKey().contains("$") == false) { keys.add(s3Object.getKey()); } } return keys; }
public void delete(String path) { try { m_s3service.deleteObject(BUCKET, path); m_logger.trace("DeleteObject: {}", path); } catch (Exception e) { throw new RuntimeException(e); } } }
@Override public void purge(String prefix) throws IOException { String key = ""; try { S3Object[] objects = s3Service.listObjects(bucket.getName(), prefix, null); for (S3Object object : objects) { key = object.getKey(); s3Service.deleteObject(bucket, key); } } catch (S3ServiceException e) { handleException(e, key); } }
bucket = s3Service.createBucket(bucketName); credsObject.setDataInputStream(bais); credsObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ); s3Service.putObject(bucket, credsObject); System.out.println("Is bucket accessible? " + s3Service.isBucketAccessible(bucketName)); S3Object retrievedCredsObject = s3Service.getObject(bucket, credentialObjectName);
public static void deleteBucket(String bucketName, String awsAccessKey, String awsSecretKey) { try { System.out.println(""); System.out.print("Deleting Bucket [" + bucketName + "]"); AWSCredentials bawsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey); S3Service bs3Service = new RestS3Service(bawsCredentials); S3Object[] obj = bs3Service.listObjects(bucketName); for (int i = 0; i < obj.length; i++) { bs3Service.deleteObject(bucketName, obj[i].getKey()); System.out.print("."); } bs3Service.deleteBucket(bucketName); SDFSLogger.getLog().info("Bucket [" + bucketName + "] deleted"); System.out.println("Bucket [" + bucketName + "] deleted"); } catch (ServiceException e) { SDFSLogger.getLog() .warn("Unable to delete bucket " + bucketName, e); } }
public void put(String path, byte[] value) { try { S3Object obj = new S3Object(path, value); m_s3service.putObject(BUCKET, obj); m_logger.trace("PutObject: {}", path); inc(); } catch (Exception e) { throw new RuntimeException(e); } }
public void run() { try { if (headOnly) { if (signedGetOrHeadUrl == null) { result = s3Service.getObjectDetails(bucket, objectKey); } else { SignedUrlHandler handler = s3Service; result = handler.getObjectDetailsWithSignedUrl(signedGetOrHeadUrl); } } else { if (signedGetOrHeadUrl == null) { result = s3Service.getObject(bucket, objectKey); } else { SignedUrlHandler handler = s3Service; result = handler.getObjectWithSignedUrl(signedGetOrHeadUrl); } } } catch (ServiceException se) { result = new S3ServiceException(se); } }
public void run() { try { List allObjects = new ArrayList(); List allCommonPrefixes = new ArrayList(); do { StorageObjectsChunk chunk = s3Service.listObjectsChunked( bucketName, prefix, delimiter, maxListingLength, priorLastKey); priorLastKey = chunk.getPriorLastKey(); allObjects.addAll(Arrays.asList(chunk.getObjects())); allCommonPrefixes.addAll(Arrays.asList(chunk.getCommonPrefixes())); } while (!halted && priorLastKey != null); result = new S3ObjectsChunk( prefix, delimiter, (S3Object[]) allObjects.toArray(new S3Object[allObjects.size()]), (String[]) allCommonPrefixes.toArray(new String[allCommonPrefixes.size()]), null); } catch (ServiceException se) { result = new S3ServiceException(se); } }
@Override public void delete() throws IOException { // Note: DELETE on a non-existing resource is a successful request, so we need this check if(!exists()) throw new IOException(); try { // Make sure that the directory is empty, abort if not. // Note that we must not count the parent directory (this file). boolean isDirectory = isDirectory(); if(isDirectory && service.listObjectsChunked(bucketName, getObjectKey(true), "/", 2, null, false).getObjects().length>1) throw new IOException("Directory not empty"); service.deleteObject(bucketName, getObjectKey(isDirectory)); // Update file attributes locally atts.setExists(false); atts.setDirectory(false); atts.setSize(0); } catch(S3ServiceException e) { throw getIOException(e); } }
S3Bucket[] bucketArray; try { bucketArray = s3.listAllBuckets(); for (S3Bucket s3Bucket : bucketArray) { DefaultMutableTreeNode tempTreeNode = s3Tree.addObject((DefaultMutableTreeNode) null, return; S3Object[] s3ObjectArray = s3.listObjects(s3Bucket.getName()); for (S3Object s3Object : s3ObjectArray) { String keyName = s3Object.getName();
S3Service.buildPostForm("public-bucket", "${filename}"); S3Service.generatePostPolicyCondition_Equality("bucket", BUCKET_NAME), S3Service.generatePostPolicyCondition_Equality("key", key), S3Service.generatePostPolicyCondition_Range(10240, 204800), S3Service.generatePostPolicyCondition_Equality("acl", "public-read"), S3Service.generatePostPolicyCondition_Equality("Content-Type", "image/jpeg"), S3Service.generatePostPolicyCondition_Equality("success_action_redirect", "http://localhost/post_upload") }; String restrictedForm = S3Service.buildPostForm( BUCKET_NAME, key, awsCredentials, expiration, conditions, inputFields, null, true); devPayService.listAllBuckets(); cal.add(Calendar.MINUTE, 5); String signedDevPayUrl = devPayService.createSignedGetUrl( "devpay-bucket-name", "devpay-object-name", cal.getTime());
/** * Puts an object inside an existing bucket in S3, creating a new object or overwriting * an existing one with the same key. * <p> * This method can be performed by anonymous services. Anonymous services * can put objects into a publicly-writable bucket. * * @param bucket * the bucket inside which the object will be put, which must be valid. * @param object * the object containing all information that will be written to S3. At very least this object must * be valid. Beyond that it may contain: an input stream with the object's data content, metadata, * and access control settings.<p> * <b>Note:</b> It is very important to set the object's Content-Length to match the size of the * data input stream when possible, as this can remove the need to read data into memory to * determine its size. * * @return * the object populated with any metadata information made available by S3. * @throws S3ServiceException */ public S3Object putObject(S3Bucket bucket, S3Object object) throws S3ServiceException { try { assertValidBucket(bucket, "Create Object in bucket"); return putObject(bucket.getName(), object); } catch (ServiceException se) { throw new S3ServiceException(se); } }
public void deleteAll(String path) { try { String priorLastKey = null; while(true) { StorageObjectsChunk chunk = m_s3service.listObjectsChunked(BUCKET, path, "?", CHUNK_SIZE, priorLastKey); m_logger.trace("ListObjects to delete: {}", path); inc(); StorageObject[] objects = chunk.getObjects(); if(objects.length == 0) break; String[] names = new String[objects.length]; for(int i = 0; i < objects.length; i++) { names[i] = objects[i].getKey(); } m_s3service.deleteMultipleObjects(BUCKET, names); m_logger.trace("DeleteObjects: {}", objects.length); // do not inc() because delete requests are not counted if(chunk.isListingComplete()) break; priorLastKey = chunk.getPriorLastKey(); } } catch (ServiceException e) { throw new RuntimeException(e); } }
assertAuthenticatedConnection("Get or Create Bucket with location"); } catch (ServiceException se) { throw new S3ServiceException(se); S3Bucket bucket = getBucket(bucketName); if (bucket == null) { bucket = createBucket(new S3Bucket(bucketName, location));
@Override public void copy(String srcKey, String dstKey) throws IOException { try { if(LOG.isDebugEnabled()) { LOG.debug("Copying srcKey: " + srcKey + "to dstKey: " + dstKey + "in bucket: " + bucket.getName()); } if (multipartEnabled) { S3Object object = s3Service.getObjectDetails(bucket, srcKey, null, null, null, null); if (multipartCopyBlockSize > 0 && object.getContentLength() > multipartCopyBlockSize) { copyLargeFile(object, dstKey); return; } } S3Object dstObject = new S3Object(dstKey); dstObject.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm); s3Service.copyObject(bucket.getName(), srcKey, bucket.getName(), dstObject, false); } catch (ServiceException e) { handleException(e, srcKey); } }
public void run() { try { result = s3Service.createBucket(bucket); } catch (S3ServiceException e) { result = e; } }
public FileMetadata retrieveMetadata(String key) throws IOException { try { S3Object object = s3Service.getObjectDetails(bucket, key); return new FileMetadata(key, object.getContentLength(), object.getLastModifiedDate().getTime()); } catch (S3ServiceException e) { // Following is brittle. Is there a better way? if (e.getMessage().contains("ResponseCode=404")) { return null; } if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new S3Exception(e); } }
@Override public S3Bucket createBucket(String bucketName) throws S3ServiceException { try { return this.createBucket(bucketName, getJetS3tProperties().getStringProperty( "s3service.default-bucket-location", "US"), null); } catch (ServiceException se) { throw new S3ServiceException(se); } }
/** * Returns an object representing the details of an item in S3 without the object's data, and * without applying any preconditions. * * @deprecated 0.8.0 * * <p> * This method can be performed by anonymous services. Anonymous services * can get a publicly-readable object's details. * * @param bucket * the bucket containing the object. * This must be a valid S3Bucket object that is non-null and contains a name. * @param objectKey * the key identifying the object. * @return * the object with the given key in S3, including only general details and metadata (not the data * input stream) * @throws S3ServiceException */ @Deprecated public S3Object getObjectDetails(S3Bucket bucket, String objectKey) throws S3ServiceException { try { assertValidBucket(bucket, "getObjectDetails"); return getObjectDetails(bucket, objectKey, null, null, null, null); } catch (ServiceException se) { throw new S3ServiceException(se); } }