Open luv2manish opened 10 months ago
If you provide more useful information, maybe I can take a look at this issue sometime.Not everyone is willing to spend time figuring out what S3 Bucket is.
obviously it is possible
This is totally possible. Just get an InputStream
from AWS libraries and use it.
Get InputStream
public InputStream getS3FileInputStream(@NonNull final String key,@NonNull final String bucket) {
log.debug("Reading file with key {} from S3 bucket {}", key, bucket);
final GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
return new S3InputStream(getAmazonS3()
.getObject(getObjectRequest)
.getObjectContent());
}
Helper Class
@RequiredArgsConstructor
@Getter
@EqualsAndHashCode(callSuper = true)
public static class S3InputStream extends InputStream {
private final InputStream is;
@Override
public int read() throws IOException {
return is.read();
}
@Override
public void close() throws IOException {
try {
IOUtils.drainInputStream(is);
} catch (final Exception e) {
// ignore
}
is.close();
}
}
Use InputStream
try (
final InputStream inputStream = userFileService.getInputStream(userFile)
) {
doSomethingWithInputStream(inputStream)
} catch (final IOException e) {
// ...
}
Open Workbook and Sheet
public void doSomethingWithInputStream(@NonNull final InputStream inputStream)
try(
final Workbook workbook=new ReadableWorkbook(inputStream)
){
final Stream<Sheet> sheetStream=workbook.getSheets();
// ...
} catch(final IOException e){
// ...
}
im trying to read excel files kept on S3 Bucket , somehow its not working