I have a small js program that uploads an image to my gcs bucket. If this happens, my gcs will send a notification to the servlet in the google engine.
So far so good. Now my servlet should read from gcs and download the file that was downloaded minutes ago. Then I want to parse it into an image object and resize the image. The new image should be loaded into another gcs bucket.
To communicate with gcs, I use gcs client lybrary.
GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
GcsFilename filename = new GcsFilename("bucket_name", "image_name");
GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(filename, 0, 1024 * 1024);
try ( ObjectInputStream inputStream = new ObjectInputStream(Channels.newInputStream(readChannel))){
inputStream.readObject();
log(inputStream.getClass().getName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
I also tried storing it in a byte array, but the error is always the same
Do not throw exception from servlet java.io.StreamCorruptedException: invalid stream header: FFD8FFE0
what am I doing wrong? Did I forget something? Thank you for your help.