0

i have uploaded small file to amazon s3 bucket easily in java. but when i uploading large file with 50MB it is taking too long time i am not even getting exception but file is not uploading. my code is simple

s3client.putObject(new PutObjectRequest("dev.rivet.media.web", "all.wav",new File(file path)));

can any one please suggest me to over come this problem

1 Answer 1

6

Alternatively you can take a look at https://github.com/minio/minio-java

Minio Java library provides simpler API's to access S3 Compatible storage providers.

In this library putObject manages file upload automatically by doing multipart internally and continues from where it left off as well.

Here is an example program.

import io.minio.MinioClient;
import io.minio.errors.ClientException;
import org.xmlpull.v1.XmlPullParserException;

import java.io.FileInputStream;
import java.io.File;
import java.io.IOException;

public class PutObject {
  public static void main(String[] args) throws IOException, XmlPullParserException, ClientException {
    System.out.println("PutObject app");

    // Set s3 endpoint, region is calculated automatically
    MinioClient s3Client = new MinioClient("https://s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY");

    File f = new File("C:/java/hello");
    InputStream f = new FileInputStream(f);

    // create object
    s3Client.putObject("bucketName", "objectName", "application/octet-stream",
                       f.length(), f);
  }
}

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.