aboutsummaryrefslogtreecommitdiff
path: root/other/java
diff options
context:
space:
mode:
Diffstat (limited to 'other/java')
-rw-r--r--other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/PutObject.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/PutObject.java b/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/PutObject.java
index 021d01e34..9af184d2b 100644
--- a/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/PutObject.java
+++ b/other/java/s3copy/copier/src/main/java/com/seaweedfs/s3/PutObject.java
@@ -12,13 +12,21 @@ import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
+import com.amazonaws.services.s3.model.S3Object;
+import com.amazonaws.util.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.io.File;
+import java.io.IOException;
/**
* Hello world!
*/
public class PutObject {
+
+ private static Log log = LogFactory.getLog(PutObject.class);
+
public static void main(String[] args) {
AWSCredentials credentials = new BasicAWSCredentials("ANY-ACCESSKEYID", "ANY-SECRETACCESSKEY");
@@ -39,10 +47,11 @@ public class PutObject {
String fileObjKeyName = "fileObject2";
String fileName = args[0];
+ String stringContent = "Uploaded String Object v3";
try {
// Upload a text string as a new object.
- s3Client.putObject(bucketName, stringObjKeyName, "Uploaded String Object v3");
+ s3Client.putObject(bucketName, stringObjKeyName, stringContent);
// Upload a file as a new object with ContentType and title specified.
PutObjectRequest request = new PutObjectRequest(bucketName, fileObjKeyName, new File(fileName));
@@ -51,6 +60,23 @@ public class PutObject {
metadata.addUserMetadata("x-amz-meta-title", "someTitle");
request.setMetadata(metadata);
s3Client.putObject(request);
+
+ S3Object written = s3Client.getObject(bucketName, stringObjKeyName);
+
+
+ try {
+ String expected = IOUtils.toString(written.getObjectContent());
+
+ if (!stringContent.equals(expected)){
+ System.out.println("Failed to put and get back the content!");
+ }
+
+ } catch (IOException e) {
+ throw new SdkClientException("Error streaming content from S3 during download");
+ } finally {
+ IOUtils.closeQuietly(written, log);
+ }
+
} catch (AmazonServiceException e) {
// The call was transmitted successfully, but Amazon S3 couldn't process
// it, so it returned an error response.