Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert FileInputStream to S3ObjectInputStream

I want to convert a FileInputStream to a S3ObjectInputStream.

This is my current code:

InputStream is = new FileInputStream(file);
S3ObjectInputStream sObject = (S3ObjectInputStream)is;

However, it's giving the error:

java.io.FileInputStream cannot be cast to com.amazonaws.services.s3.model.S3ObjectInputStream
like image 776
Ivory Avatar asked Nov 23 '22 06:11

Ivory


1 Answers

Use the below constructor to convert an InputStream to a S3ObjectInputStream:

var s3ObjectInputStream = new S3ObjectInputStream(inputStream, null);

You can safely use null for the 2nd argument in the constructor (HttpRequestBase) as the abort method which uses it, isn't available in the cast InputStream.

like image 170
Ranjani Nataraja Sharma Avatar answered Jan 23 '23 00:01

Ranjani Nataraja Sharma