Answer the question
In order to leave comments, you need to log in
How to store blob in db?
There is a link like
blob:http://localhost:8080/ad028394-c137-4842-aeeb-24c74fea28de
received as a result new Blob([file], { type: "image/png" });
and subsequent URL.createObjectURL(blob)
, when you try to display this link in img
, an error occursGET blob:http://localhost:8080/ad028394-c137-4842-aeeb... net::ERR_FILE_NOT_FOUND
The generated url is only valid while the current document is open.
Answer the question
In order to leave comments, you need to log in
If it happens in the browser, you can save the files in IndexedDB and they will remain there even after reloading the page. To store a file in IndexedDB , first include the localforage library on the page :
<script src="https://cdnjs.cloudflare.com/ajax/libs/localforage/1.9.0/localforage.min.js"></script>
async function saveFile(file) {
var result = await localforage.setItem('file', file);
console.log('Файл сохранён:');
console.dir(result);
}
async function getFile() {
var file = await localforage.getItem('file');
document.querySelectror('img').src = URL.createObjectURL(file);
console.log('Файл вставлен:');
console.dir(file);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question