Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

493
Views
How to get the image stored into my mysql database in blob format on my google sheet?

I have a google sheet connected to my MySQL database with a Google script. I'm able to retrieve all the text data I want instead of the blob stored in the database. Here is the php code:

$insert = $conn->query("INSERT into images (image) VALUES ('$base64Img')");

I only left one field to make it clear

The blob column in the table is set to "LONGBLOB". How can I view my BLOB as an image in my google sheet?

Here is what I tried :

function readFromTable() {
  var conn = Jdbc.getConnection(url, username, password);
  var stmt = conn.createStatement();
  stmt.setMaxRows(1000);
  var results = stmt.executeQuery('SELECT image FROM images');
  var numCols = results.getMetaData().getColumnCount();
  var spreadsheet = SpreadsheetApp.getActive();
  var sheet = spreadsheet.getSheetByName('Sheet1');
  var arr=[];
  while (results.next()) {
    var arr = [];
    for (var col = 0; col < numCols; col++) {
      arr.push(results.getBlob(col + 1));
    }
    sheet.appendRow(arr);
  }

  results.close();
  stmt.close();
}

I don't get any error message but on my sheet it prints : JdbcBlob in the cell instead of the actual image. I would like to put the image into a cell of my google sheet

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

  • Get JdbcBlob from JdbcResultSet
  • Get AppsScriptBlob from JdbcBlob
  • 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)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!