5

I have my application hosted on AWS, Elastic Beanstalk - Tomcat 6. My data files are stored in an S3 bucket. When I am hosting my application on local server on my machine , I am able to read and write data to my S3 bucket (using via SDK), but from the application hosted on Elastic Beanstalk the writing operation is showing an error i.e on Elastic Beanstalk Tomcat. I am getting below error:

com.amazonaws.AmazonClientExceptio­n: Unable to calculate MD5 hash: visitorsinfo.json (No such file or directory)

I do have visitorsinfo.json in my S3 bucket which is successfully accessible from my local server in my machine, but not accessible from Elastic Beanstalk..

Mark B
  • 183,023
  • 24
  • 297
  • 295
user3112954
  • 155
  • 1
  • 2
  • 7
  • EBS = Elastic Block Store. Are you referring to Elastic Beanstalk? – Mark B Sep 04 '16 at 21:12
  • 2
    Also, the key part of that error message is `No such file or directory` not `Unable to calculate MD5 hash` which you seem to be focusing on. The file doesn't actually exist. – Mark B Sep 04 '16 at 21:13
  • Hi, Its Elastic Beanstalk, The file is present and it is modified when i point my local machine to the same bucket.. Its quite strange behavior, Any guess? – user3112954 Sep 05 '16 at 17:01
  • Add some code to print out the full bucket and key for the S3 object, perhaps it is using an incorrect key prefix on the server? – Mark B Sep 05 '16 at 17:03
  • HI, got this resolved by creating new application with 64bit Amazon Linux 2014.03 v1.1.0 running Tomcat 7 Java 6 – user3112954 Sep 05 '16 at 19:04

3 Answers3

7

Instead of passing file object pass the Input Stream to the put object as shown below

InputStream is=file.getInputStream();                                                                           
s3client.putObject(new PutObjectRequest(bucketName, keyName,is,new ObjectMetadata())); 
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
Amit Gujarathi
  • 1,090
  • 1
  • 12
  • 25
  • @SkyWalker can you explain me how using InputStream instead of a file will fix the problem ? – KidWithAComputer Nov 19 '20 at 10:25
  • @PrakharVerma please check https://stackoverflow.com/a/28569038/2293534 – SkyWalker Nov 19 '20 at 10:32
  • @SkyWalker I am still skeptical about this.. I have checked the intenal implementaion of function where File is passed. File was converted to FIleInputStream. Sharing code below of AWS SDK – Aditya Rewari May 13 '23 at 21:14
  • public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws SdkClientException, AmazonServiceException { putObjectRequest = (PutObjectRequest)this.beforeClientExecution(putObjectRequest); this.rejectNull(putObjectRequest, "The PutObjectRequest parameter must be specified when uploading an object"); File file = putObjectRequest.getFile(); InputStream isOrig = putObjectRequest.getInputStream(); String bucketName = putObjectRequest.getBucketName(); – Aditya Rewari May 13 '23 at 21:14
-1

Got this resolved by creating a new application with configuration 64bit Amazon Linux 2014.03 v1.1.0 running Tomcat 7 Java 6

user3112954
  • 155
  • 1
  • 2
  • 7
-1

Man, i have the same problem. But for me, i was forget to set permissions to read files before to send the file. Just this

ActivityCompat.requestPermissions(activity!!, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE), 300)