NodeJS - Save File/Image to MySQL by Sequelize with BLOB type » grokonez

NodeJS - Save File/Image to MySQL by Sequelize with BLOB type » grokonez

In the tutorial, we will show how to build a NodeJS application to save files/images to MySQL database by Sequelize with BLOB type. Related posts: – Sequelize ORM – Build CRUD RestAPIs with NodeJs/Express, Sequelize, MySQL ContentsSequelize save file/image to MySQLPracticeSetting up NodeJS projectSequelize Image modelConfigure Sequelize MySQL ConnectionSave File/Image to MySQLRun & Check resultsSourcecode … Continue reading "NodeJS – Save File/Image to MySQL by Sequelize with BLOB type"

https://grokonez.com/node-js/nodejs-save-file-image-to-mysql-by-sequelize-with-blob-type

NodeJS – Save File/Image to MySQL by Sequelize with BLOB type

In the tutorial, we will show how to build a NodeJS application to save files/images to MySQL database by Sequelize with BLOB type.

Related posts:

Sequelize save file/image to MySQL

Firstly, we define a Sequelize model for files/images with BLOB type as below:

const Image = sequelize.define('image', {

  ...
  data: {
    type: Sequelize.BLOB('long')
  }
});

To read/write data of file/image, we use fs.readFileSync('/path/to/file') and fs.writeFileSync('/path/to/file', image.data) functions of NodeJS file-system module.

Below segment code is used to store file/image to MySQL:


var fs = require('fs');

...

var imageData = fs.readFileSync('/path/to/file');

Image.create({
    ...
    data: imageData
}).then(image => {
    try{
        fs.writeFileSync('/path/to/file', image.data);                
    }catch(e){
        console.log(e);
    }
})

Practice

We build a NodeJS project as below structure:

More at:

https://grokonez.com/node-js/nodejs-save-file-image-to-mysql-by-sequelize-with-blob-type

NodeJS – Save File/Image to MySQL by Sequelize with BLOB type

node sequelize blob image

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Node JS Resize Image Before Upload Example

In this node js tutorial, you will learn how to resize image before upload using multer, sharp with node js and express js

Image Processing in Node.js with Jimp

In this video, I will be showing you the powerful library Jimp for image manipulation in Node.js 🔴 Subscribe for more https://www.youtube.com/channel/UCMA8gV...

Image Processing in Node.js with Jimp

In this video, I will be showing you the powerful library Jimp for image manipulation in Node.js 🔴 Subscribe for more https://www.youtube.com/channel/UCMA8gV...

Hire Top Node JS Developers | Best Node.js Development Company India

Hire dedicated Node JS developers & programmers in India for custom full-stack NodeJS web development projects on hourly/full-time basis. Strict NDA, 16+ years exp & 2500+ clients|450+ Experts

Hire Dedicated Node.js Developers - Hire Node.js Developers

Get business-centric Node.Js development services from expert Node.JS developers. We have expertise in developing & maintaining Node JS apps as per the business requirements.