I want to send an image to MySQL blob feild using node.js and use Angular to display that blob as an image.
Any ideas how to do it?
It would be better if you upload image file on server and get its path and store that path in MySQL database.
for example if user wants to upload test.jpg
on server save it like : server/images/test.jpg
then insert saved path to MySQL
and on front-end retrieve image path and bind to src property of image tag.
saving blobs to database will result in slow response when you will fetch records.
you can see more details here: https://blog.jscrambler.com/implementing-file-upload-using-node-and-angular
Related
Looking for some guidance here. I am building Nodejs/Express app with MySQL Database. I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database. I using:
$('#file-input').trigger('click').change (function(){
alert($('#file-input').val());
})
I get C:/fakepath... for image location. I would like to how to upload/save selected image to the MySQL database. Connection to database is established, and routes for regular data work just fine.
Before answering your question will suggest you to not save image into your MySql or any database, use IPFS, local application directory/folder, or best AWS s3 bucket.
You can use busboy.js NPM module or multer.js NPM module for file upload to server, there's lots of good reason to not save any kind of file in local database.
Now back to how you can save image in database. You can do so by first converting your image to a data format your MySql understand. By default image is binary and depending upon image selected some image binary is so big that even MySql text datatype is small for them. Converting binary to hexadecimal does help but still too big for MySql text datatype. Also you will need multipart/form-data for file upload.
You can easily find "How to upload file in nodeJs?" in a google search. Still if need an example here's one "Upload file using multer.js"
How can I insert an image data in MySQL Database and then retrieve it using Golang?
Basically I want that task for upload profile picture of user in web application.
According to the my knowledge,the best solution is save image as blob object in database.Is it best solution for upload image in webapplication in golang.?
Please help me find the best solution for that.I want to find the solution in golang.I am beginner for golang programming.
converting image to a blob and save it in the database is a somewhat long process and it may cause issues sometimes. The easiest way is saving the image to a server (or a local directory) and saving the image path in the database. In that way we can access the image by using the image path in the database. This, will show how to save image path and access it and converting image to a blob and save it in the database.
Here
Im wondering is it possible to get the file path of an image or video data stored as blob in a MySQL database. I simply uploaded a video file through phpMyAdmin to my database and I need to know the url address of the video file.
Actually I have to upload 20000 images into mysql database if I store all images to Mysql database as Blob type the performance is reduced and It will slow down if we upload other images if required.To avoid this problem I am storing all images into folder and their path's into mysql database table.and retriving these images with pagination .
now data is showing in table but images are not displaying.
String sb1 = new String("file://");
String sb2=new String(user.getPlaceImage());
out.println("<td><img src="+sb1.concat(sb2)+" width='70' height='50' /></td>");
If there is any alternative way to deal with this problem?
Here is a basic alternative technique that I use to serve images to users:
Create a folder outside your website root so users won't have direct access to the files using HTTP. Let's say you already have a database table that contains URI to all the images. Create a interface file, for instance: getimage.jsp?id=42 that serves user the requested image file. Also, if you are storing relative URLs in the database you need to be extra careful because you might be trying to read the file from a wrong path in relation to your JSP file that's trying to access the image.
Hi i am writing a converter from Oracle to mysql
In Oracle the images are stored in db.
I want to read the content of the image and save to file system
I suppose that i have to read the blob entry and using php file commands create the file (am i right)
What about image type. Should i save as jpg (what if the store image is not jpg)
Any suggestion are welcome
you can write the blob directly to a file on disk. you can exclude the file extension from the name if you don't have that information somewhere in the db or the app. you could also deduce the content type by using the unix file command if you really need to assign an extension.