-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to read excel files from S3 Bucket #330
Comments
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 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){
// ...
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
im trying to read excel files kept on S3 Bucket , somehow its not working
The text was updated successfully, but these errors were encountered: