'Electron Blob MySQL

I would like to save and retrieve binary files from an mysql database in an Electron application. I am using mysql2/promise library to interface with mysql. I have created a binary blob base on hex and tried to send through IPC to main.js, from the index.html and prerender.js pages. However, when I send, it gives an error that the object cannot be cloned. I am unsure how to do this properly and am looking for guidance. Below is the partial code that I have been trying to test.

Main.js


    ipcMain.handle('saveBlob', async (event,data) => {
        const connection = await mysql.createConnection({
         host: 'localhost',
         database: 'somedb',
         user: 'blah',
         password : 'blah',
         port : xxxx
       }); 
    
     var parentId=1
     var result = await connection.execute("INSERT INTO somedb.files (parentId, 
     data) VALUES(?,?)", [parentId, data]);
     return result;
     })



prerender.js


const { contextBridge, ipcRenderer } = require('electron');
    
    contextBridge.exposeInMainWorld('electronAPI', {
        
        sendBlob: (ablob) => {
            ipcRenderer.invoke('saveBlob', ablob);
        }
    })


Index.html

var blob = new Blob([byteArray], {type: "application/octet-stream"});
window.electronAPI.sendBlob(blob);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source