1

I am trying to fetch from S3 bucket but I am getting key as null.

Here is my code :

    @Value("${base.location}")
    private String keyname;

    @Value("${os.s3.key}")
    private String fileName;

    @Autowired
    ReadFromS3 readFromS3;

    StringBuilder fileURI = new StringBuilder(keyname);
    fileURI.append(fileName);
  
    InputStream ts = readFromS3.getResourceStream(fileURI.toString()); //null Pointer Exception

Here is my application.properties file

           base.location=option/output_files
           os.s3.key =${S3_KEYNAME}
           S3_KEYNAME =MY_FILE.txt

Here is my getResourceStream method

@Override
public InputStream getResourceStream(String keyName) {

    S3ObjectInputStream s3objectStream = s3client.getObject(new GetObjectRequest(bucketName, keyName))
            .getObjectContent();
    return s3objectStream; // The specified key does not exist.
}

I added Loggers and the keyname is option/output_files/MY_FILE.txt

I don't understand what it means with the "specified key".

  • Does this answer your question? [Amazon S3 exception: "The specified key does not exist"](https://stackoverflow.com/questions/28653249/amazon-s3-exception-the-specified-key-does-not-exist) – Nowhere Man Oct 02 '20 at 18:20
  • What is the value of `keyName`? It should _not_ start with a slash. – John Rotenstein Oct 03 '20 at 08:29
  • @JohnRotenstein value of key name is MY_FILE.txt , I have corrected the keyname in the question – Varsha Kumari Oct 05 '20 at 12:32
  • I suggest you **add some debug statements** to see the true value of `bucketName` and `keyName` that are passed to `getObject()` since it is saying that the object doesn't exist. They might not be what you expect! – John Rotenstein Oct 05 '20 at 23:34

0 Answers0