Display all images stored as BLOB data from MySQL database
First you need to remove the if(isset($_GET['id'])
statement because you want to display all images.
Next, query all images by changing your query to query without an id
$query = mysql_query("select * from `blob`");
Next, store the image data to an array.
$images = array();
while ($row = mysql_fetch_assoc($query)) {
$images[] = $row['image'];
}
Finally, display all images. (Got the code to display multiple blobs from here)
/* header should be removed
header("content-type: image/jpeg"); */
foreach ($images as $image) {
echo '<img src="data:image/jpeg;base64,'. base64_encode($image) .'" />';
}
Retrieve an Image stored as BLOB on a MYSQL DB
On your ResultSet
call:
Blob imageBlob = resultSet.getBlob(yourBlobColumnIndex);
InputStream binaryStream = imageBlob.getBinaryStream(0, imageBlob.length());
Alternatively, you can call:
byte[] imageBytes = imageBlob.getBytes(1, (int) imageBlob.length());
As BalusC noted in his comment, you'd better use:
InputStream binaryStream = resultSet.getBinaryStream(yourBlobColumnIndex);
And then the code depends on how you are going to read and embed the image.
How to get the image stored into my mysql database in blob format on my google sheet?
- Get
JdbcBlob
fromJdbcResultSet
- Get
AppsScriptBlob
fromJdbcBlob
- Insert
AppsScriptBlob
to sheet as image
const jdbcBlob = results.getBlob(col + 1);
const appsScriptBlob = jdbcBlob.getAppsScriptBlob();
sheet.insertImage(appsScriptBlob,1,1);
//if image data is base64 encoded:
sheet.insertImage(Utilities.newBlob(Utilities.base64Decode(appsScriptBlob.getDataAsString())),1,1)
Another way would be to get byte array using getBytes()
:
const byteArr = results.getBytes(col + 1);
//if image data is base64 encoded:
sheet.insertImage(Utilities.newBlob(Utilities.base64Decode(Utilities.newBlob(byteArr).getDataAsString())),1,1)
How to display an BLOB image stored in MySql database?
This is what I used when I wanted to do something like that... a long time ago! =P
$sql = "SELECT image FROM table WHERE cond ORDER BY xxxx DESC LIMIT 5";
$result = mysqli_query($db,$sql);
while($arraySomething = mysqli_fetch_array($result))
{
echo "<img src='php/imgView.php?imgId=".$arraySomething."' />";
}
How to retrieve image blob from MySQL into C# application?
Not sure if this really counts as a "duplicate" question since it's the combination of a couple questions I found, but...
According to this you can read the BLOB as a byte[]
array:
byte[] imageBytes = (byte[])dr["headshot"];
From there, you can convert that to an Image
:
using (var ms = new MemoryStream(imageBytes))
{
headshot.Headshot = System.Drawing.Image.FromStream(ms);
}
Related Topics
How to Compile Multiple Java Source Files in Command Line
Unsatisfieddependencyexception: Error Creating Bean with Name
JSONobject - How to Get a Value
Find the Most Popular Element in Int[] Array
Export PDF Pages to a Series of Images in Java
How to Calculate the Number of Days in a Period
How to Upload Files on Server Folder Using Jsp
What Is the Equivalent of Java Static Final Fields in Kotlin
Which Loop Has Better Performance? Why
Fastest Way to Iterate an Array in Java: Loop Variable VS Enhanced for Statement
Differencebetween Lowagie and Itext
How to Delete a Folder with Files Using Java
How to Analyze Information from a Java Core Dump
Why Should One Use Objects.Requirenonnull()
Java.Lang.Classnotfoundexception: Org.Springframework.Boot.Springapplication Maven