1 year ago
#388832
Sebastián Ardila
DB malformed after downloading it from S3 bucket
I have a .db file stored in an S3 bucket. I am trying to download it to a project so I can use it for a SQLite DB. THe problem is that when I download it and use it I get the next error:
SQLITE_CORRUPT: database disk image is malformed
When I try to download it using AWS GUI I can use it perfectly to build the database. Here is the code I am using:
export async function downloadDB(cb: Function){
logger.info("Beggining downloading")
var s3 = new AWS.S3();
var params = {Bucket: 'test-bucket', Key: 'data.db'};
s3.getObject(params, (err: any, data: any) => {
fs.writeFile("./tmp/db/data.db", data.Body.toString(), (err: any) => {
if(err) throw new Error(err);
else {
logger.info(`Downloaded DB`);
cb();
}
});
})
}
export function connectToDB(){
try{
downloadDB(() => {
logger.info("Beggining connection to DB");
connection = new sqlite3.Database(path.resolve(__dirname,'../../tmp/db/data.db'), sqlite3.OPEN_READWRITE);
logger.info("Connection successful")
return connection;
});
}
catch(e){
logger.error(`${e}`);
throw e;
}
}
node.js
amazon-s3
node-sqlite3
0 Answers
Your Answer