How can I store an image in MySQL database using Razor Pages? - mysql

I am learning web development and working on Razor Pages. For my last assignment I was asked to make a website. In my website people can upload images and others see these images. The problem is I dont know how to store those photos. My tutor said if I save them in my sql table as binary values, that makes it very slow. I have to find another way. Can I convert image inputs to Url and store them as "text" ? Or is there any other solution?

You can save the file to the file system (wwwroot/images, for example) and the file name of the image in the database. Then construct the value for the src attribute from the saved filename:
<img src="/images/#Model.ImageFileName" alt="..." />
My tutor said if I save them in my sql table as binary values, that
makes it very slow.
I can't speak with any authority on MySQL, but you should test to see if there is actually a performance penalty, and if so, whether it's significant.

Store the Uploaded files in the File System and insert the path of the saved file in the DB.
This will help you to maintain the DB performance.
Thanks

Related

Rails upload a file and render it as an HTML page

I am building a website with ROR 3. I need to provide a page to my clients wherein he could edit his pricing info regarding the application. I am quite confused on how to do this. The pricing page needs to be displayed as an html table with different columns which has got the pricing info.
I am thinking of different ways to do this.
1) Allow the client to create and upload an html page and then save it as a file in my public directory and render as an when the client clicks on the pricing link.
2) The clients may not have bare technical knowledge, hence make the client upload some other formats like Word, Excel etc and then parse it and store it as an HTML file in the public directory.
3) Provide the client with some real time editing tools where in the client could edit in a fixed format, and after wards save the file and render it later.
Also, I wouldn't like to store these infos in my database. There would be quite a few number of clients and hence managing all these data in my database would become cumbersome. Storing all these as plain html files and rendering it later would be the most ideal thing for me.
There might be other better steps in doing this as well. Could you please suggest which might the better, or any other option that could suit my needs? Basically I would want my clients to have a mechanism where they could provide there pricing details, edit it later and display it back as an html table, all this without using an Database backend. Any suggestions would be mostly appreciated.
Good way is Excel(csv format).
You can do PHP with Excel. I thing this is the best solutions for your requirement.
Try this.
http://php.net/manual/en/function.fgetcsv.php
If you are give authority to user to change edit contain and you have to used " CSV or Excel" please see these links:
Importing CSV and Excel
Exporting CSV and Excel
If you really don't want to use database then you can use YAML as a structured storage.
e.g. ( you, most probably, could come up with a better structure )
SMS_Pack:
Sl_No:
1: 10000
2: 25000
3: 50000
You can read those .yml files and parse them as hashes. Should be fairly easy to represent that hash as a HTML table.
For the creation, I'm sure you can come up with some dynamic form input. Or to just let the client send this kind of file ( which might not be the best solution ).
But it just might be easier to manage all of this information within a database.

download image directory from server and store on iphone

I am trying to create a business directory application for my area, I am currently trying to create a sql DB with all of the realivant business information (name, address, opening hours etc). I am then plan to have a physical file directory where all logo images are stored, this directory will be stored somewhere on the server.
When the user starts the applicatoin they will be prompted to download all of the information on business listings (because its for a small community), I will then upload all of the data to the phone using NSURLConnection, the data will be Zlib NSData in the form of XML. I will store all of this data into coredata (which will act as the apps cache).
The next step is to download the directory of images I have stored on the DB.. but I have no idea on the best approach for this and would like some guidance, example code etc.
For instance would it be better to store the images into the sqlDB? I have read this is a bad idea so am trying the approach explained above.
I am still in the process of building the sqlDB but the difficulty I am having is comming up with a way to get the images onto the device and relate them to the correct business using an id field or something simlar.. or is there an easier way to do this?
any help would be appreciated.
Instead of storing the image directly in the DB, you could store the URL to access the image binary instead. This would maintain the relationship with the image without storing the large image data directly in the DB. You could then use the URL retrieved from the DB to download the image on the device and similarly store the path to the downloaded cached image in core data.

Storing text/image file in mysql database

Is it possible to store .doc/.txt or image files to stroe in database directly making attributes of type blob?I neewd a good working example for storing files inside database and also obviously retrieving them from database as original.
The blog entry http://mirificampress.com/permalink/saving_a_file_into_mysql describes the overall process in quite allot of detail for php.

Saving pictures in the a MySQL DB vs saving it as file

I know this question was asked in various ways here, but none of the answer is conclusive.
I have a system which among other things updates a website gallery.
I can both "upload" the file to the website (and save a copy at the system - needed) or just save it in the DB and save the space (and another upload). If I go with the files I would need to "notify" the webpage of every change (picture delete, add or change) instead of just making the change in the DB.
So:
If we are talking about a standard website with a picture gallery, is it best to save the pictures as pictures or in the DB?
If the webpage is very visited or very large, does it makes any difference?
Is the difference that significant? Or just go with the convenient way?
Although I presented my case I would like also to have a "more in general" answer, what is the "good" approach when talking about saving files.
Thanks in advance for clarifying it,
Michel.
Only put structured data in a DB. Images are files and should be kept on a files system. The performance of the DB will degrade more and more as the number of pictures / users grows. Instead create an image object which you can use to track the image location and meta data.
I have had the same problem with you in a previous project of mine.
I decided to go with only storing the path of the image in my database (which is just a string) and save the image in the file system, not in the DB.
This is the best practice in many ways.
It keeps your DB small, getting a large amount of rows is faster and DB back ups are significantly smaller.
Just put the images in a file and save the path in the DB so you can retrieve it later.

Storing image in image column of SQL Server. Is it beneficial than storing image in folder on website

I have to display images on website and I can store image in the folder on my website and also I can store the image in image column of SQL Server.
So which way of storing image is better : in folder or in Image column of SQL Server.
1. Which way of storing image and retrieving it is faster
With SQL Server 2008, while you can store BLOB data, it's best to avoid it. I've done it in the past, grudgingly, and it did have negative performance implications. Unless you have some constraint which prevents it, use the file system. That's what it's built for, and it's much faster.
As #Martin Smith pointed out you could use FileStream. We started storing our files using FileStream so that we could also add full-text indexing and allow the users to not only search the data, but the files on our site. It is also nice because we can easily move our files along with teh Database to other environments (Dev, Test).
nice file stream Article: Here
Also, please use varbinary(max) if you are going to store in the DB. The image column is going to be deprecated in future versions.
--S