I am trying to save an image file in my h2 database, but when I try to read it in testing(with a get request), it returns a String, which when transformed into bytes, is not equal to the bytes of the original image, and when the bytes are written to a file the file isnt recognised as an image. code here: https://github.com/legoaggelos/CatPlace/tree/cat-pfps. I am not sure where the bug is, but I found it in the first test in https://github.com/legoaggelos/CatPlace/blob/cat-pfps/src/test/java/com/legoaggelos/catplace/CatPlaceApplicationTests.java, after some experimenting, would appreciate help
#File saving improperly in h2 database
1 messages · Page 1 of 1 (latest)
<@&1004656351647117403> please have a look, thanks.
Changed the category to Database.
<@&987246584574140416> please have a look, thanks.
@latent nebula
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure 👍
var bytes = ((String)x).getBytes();
var actualBytes = Files.readAllBytes(Paths.get("4.jpg"));
assertThat(actualBytes).isEqualTo(bytes);``` this is an example of code that fails
Detected code, here are some useful tools:
Formatted code
var x = documentContext.read("$.profilePicture");
var bytes = ((String) x).getBytes();
var actualBytes = Files.readAllBytes(Paths.get("4.jpg"));
assertThat(actualBytes).isEqualTo(bytes);
Expected :[47, 57, 106, 47, 52, 81, 65, 87, 82, 88, 104, 112, 90, 103, 65, 65, 84, 85, 48, 65, 75, 103, 65, 65, 65, 65, 103, 65, 65, 65, 65, 65, 65, 65, 68, 47, 50, 119, 66, 68, 65, 65, 69, 66, 65, 81, 69, 66, 65, 81, 69, 66, 65, 81, 69, 66, 65, 81, 69, 66, 65 ...
Actual :[-1, -40, -1, -31, 0, 22, 69, 120, 105, 102, 0, 0, 77, 77, 0, 42, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, -1, -37, 0, 67, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 2, ...
this is what the issue is
Base64.getDecoder().decode((String) x))
needed to decode it