• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Store an image input into a MySQL table row  RSS feed

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to store a replacement image into a MySQL table row. I retrieve the original image and display it successfully. When I write the replacement image the write is successful. However, when I display the replacement image it does not display as an image. Therefore, I surmise that my write to the database was not correct. The prepared statement is:



The value in picture is (I have tried - replace(/^data:image\/(png|jpg|gif|jpeg);base64,/, ""):

data:image\gif;base64,R0lGODlhlgCWAPcAAAAAAAAAMwAAZgAAmQAAzAAA\wArAAArMwArZgArmQArzAAr\wBVAABVMwBVZgBVmQBVzABV\wCAAACAMwCAZgCAmQCAzACA\wCqAACqMwCqZgCqmQCqzACq\wDVAADVMwDVZgDVmQDVzADV\wD\AAD\MwD\ZgD\mQD\zAD\zMAADMAMzMAZjMAmTMAzDMA\zMrADMrMzMrZjMrmTMrzDMr\zNVADNVMzNVZjNVmTNVzDNV\zOAADOAMzOAZjOAmTOAzDOA\zOqADOqMzOqZjOqmTOqzDOq\zPVADPVMzPVZjPVmTPVzDPV\zP\ADP\MzP\ZjP\mTP\zDP\2YAAGYAM2YAZmYAmWYAzGYA\2YrAGYrM2YrZmYrmWYrzGYr\2ZVAGZVM2ZVZmZVmWZVzGZV\2aAAGaAM2aAZmaAmWaAzGaA\2aqAGaqM2aqZmaqmWaqzGaq\2bVAGbVM2bVZmbVmW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UTb9gOB+CKh9SKhDFrBlqXZb\ymMIgeh7yl+Dpx8xwGPPRR3I8q8o8qgkqH+Xt+E8OhEssQFam6KWzZ+YMcMMrg7w6h+Xv\EOgGFVNF+kNB+7X\Eozf+8Af\Dx8L\w3oQ+\fxa8T\zKv\xDUQ+MyvwwkfPQP\3UX\3Wf\3YfxLHn\3c\x3P3\3gH\7iP\40Yfzkf\43ERAAOw==
 
Saloon Keeper
Posts: 4787
52
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the SQL type for column 8?

I would think that an image stored in a database would be a BLOB (binary large object).
 
Glyndwr Bartlett
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SQL (MySQL) type is mediumblob and the input is string. I guess what you are telling me is that I need to convert string to mediumblob (I have read that string can be stored in blob) how do I do the conversion please?

I tried:

 
Ranch Foreman
Posts: 111
1
Android Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you can convert string to inputStream , then use setBlob.

 
Glyndwr Bartlett
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, that did not work.



Do you know if I need to do this:



or is it fine to have "data:image/gif;base64," at the start of the string?
 
Randy Tong
Ranch Foreman
Posts: 111
1
Android Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where you get the replacement image ?
 
Glyndwr Bartlett
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Front end is HTML5, bootstrap, javascript and jQuery to Ajaxa into JSON to java client side to java server side to MySQL.
 
Carey Brown
Saloon Keeper
Posts: 4787
52
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The image you've posted is not binary it is a base64 encoding of binary.
 
Glyndwr Bartlett
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a solution please? I have searched on base64 observation and tried:



This does not work either.
 
Carey Brown
Saloon Keeper
Posts: 4787
52
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What data type is "picture" and what does it contain?
 
Carey Brown
Saloon Keeper
Posts: 4787
52
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it is binary data then there's no such thing as "UTF-8" with regards to it.

How are you reading the one that works?
 
Glyndwr Bartlett
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I do not understand your question. In my original post I have the contents of the String. So I suppose the answer is I pass a string with the data above. I have seen where one solution that removed the starting characters as per my posts above. I do not know if that is required?

Kind regards,

Glyn
 
Carey Brown
Saloon Keeper
Posts: 4787
52
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you understand:
  • Binary data vs character data
  • BLOBs
  • Image file formats
  • Base64 encoding and decoding


  • You seem to indicate that you can read an existing image from the database. How are you doing that?

    You are giving us very little to go on.
     
    Glyndwr Bartlett
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I very much appreciate your help Carey.

    I read the data in from MySQL with:







    Kind regards,

    Glyn
     
    Carey Brown
    Saloon Keeper
    Posts: 4787
    52
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Glyndwr Bartlett wrote:The SQL (MySQL) type is mediumblob and the input is string. I guess what you are telling me is that I need to convert string to mediumblob (I have read that string can be stored in blob) how do I do the conversion please?

    I tried:


    A BLOB is not for String data it is for binary data.  Why is your input a String?
     
    Glyndwr Bartlett
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Carey,

    Sorry I am not a programmer. I am doing this to provide a system for recording and reporting on awards for my Scouts. I am learning as I go and doing lots of research. I see that I need to convert my base64 string; however, this is what I am struggling with. I can not find the right code.

    Kind regards,

    Glyn
     
    Glyndwr Bartlett
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Carey,

    My input is a string because that is what is passed from my input. I use HTML, bootstrap, javascript, jQuery to get the input. I then use ajax and JSON to pass the input to the client side java and then to the server side java to store. The HTML, bootstrap, javascript, jQuery is getting the image and displaying it on the page. That took a few weeks. Now I am passing the image data to be stored.

    Kind regards,

    Glyn
     
    Carey Brown
    Saloon Keeper
    Posts: 4787
    52
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This is how you are reading the image so you'll have to reverse these steps. Note that "imageDataString" may represent an image it is no longer an image, ie binary data, it's a String. So, if you were to be given an "imageDataString" to put into the database, you'd have to strip off "data:image/jpeg;base64," using substring(). Then you'd have to call decodeImage() (whatever that is?) to convert it to a byte[]. Then you'd have to use ps.setBytes​(long pos, byte[] bytes) to write out the binary data to the BLOB.
     
    Carey Brown
    Saloon Keeper
    Posts: 4787
    52
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Correction:
     
    Glyndwr Bartlett
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I found this: https://javapointers.com/tutorial/java-convert-image-to-base64-string-and-base64-to-image/

    This, and your response answers my earlier question about removing the start with"



    So now I will use this in future.

    So the code is:

                                   

    This can be simplified to:

                                  

    This does not work either. I will continue to investigate.

    Kind regards,

    Glyn
     
    Glyndwr Bartlett
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Carey,

    Thank you so much for your help! The answer is:

    As you said:



    This is done before passing to java client side. Then on the server side:



    Once again thank you very, very much.

    Kind regards,

    Glyn


     
    Carey Brown
    Saloon Keeper
    Posts: 4787
    52
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I find it useful to have a utility class to encapsulate these steps. Then call the static methods from your project. Something like
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!