Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

488
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda