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

184
Views
¿Cómo almacenar un objeto blob en la base de datos mySql?

Estoy generando blob -

 let blob = new Blob([document.querySelector("body").outerHTML], {type: 'image/png'});

La salida del código anterior en mi caso es:
ingrese la descripción de la imagen aquí

Ahora, desde aquí, quiero almacenar el blob generado en la base de datos MySQL.
Estoy usando el formato BLOB en MySQL para almacenar imágenes.
¿Cómo almacenar el objeto blob generado en MySQL?

Edición 1:
Puedo ver mi imagen en la parte inferior de la página.

 const blobUrl = URL.createObjectURL(blob); const img = document.createElement('img'); img.src = blobUrl; document.body.appendChild(img);

Pero no sé cómo almacenar esa imagen como BLOB en MySQL.
¿Alguna ayuda o alguna sugerencia?

Edición 2:
Estoy usando la estructura de la tabla como -

 CREATE TABLE images( id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, image_data LONGBLOB, image_title CHAR(50), size CHAR(50) );

Pero, ¿qué debo pasar en image_data? Solo tengo un objeto Blob generado por JavaScript.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Simplemente almacene los datos en el tipo LONGBLOB .

Envíe los datos de su imagen y el título de la imagen usando AJAX

 var data = new FormData(); data.append('title', 'Enter title here'); data.append('image', blob); $.ajax({ type: 'POST', url: 'upload.php', data: fd, processData: false, contentType: false }).done(function(data) { console.log(data); });

Luego crea una tabla en la base de database

 CREATE TABLE images( id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, image_data LONGBLOB, image_title CHAR(50) );

Ahora almacene sus datos en variables e insert en la base de database creada

cargar.php

 $image_data = $_POST['image']; $title = $_POST['title']; $sql = "INSERT INTO images(image_data,image_title) VALUES('$title','file_get_contents($image_data)')"; mysql_query($sql);
about 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!