Can I use mysql to store images and load them to my ios app? - mysql

I am new to using StackOverflow and I don't know how to properly ask this question also this is my first time using swift and some external database server.
I am creating an ios app using Xcode and I'm attempting to create an inventory to store items (300 - 1000 items) such as milk, eggs, bread etc and will have to store the product image as well as the product details such as weight, price, ingredients etc.
But I have no idea as to what to use I was thinking mysql but after doing some research I've found its best not to use blob. I've already used MySQL for the login page into the app so I assumed it was easier to use mysql for the product database as well.
The idea is the user creates an account, logs in then can view products in my made up store. I wanted to use an external database so I can give the app to friends and they can use it by downloading from the app store when it's finished.

Can you save the bytes of a large file in a database? Yes. Should you? No.
Generally speaking the proper way to handle files in a database is to store the URL of the file, not the file itself.
If the images you're using are available online and you are only need to view them, you only need to save the URL itself. There are libraries that can handle all the downloading and cacheing quite easily once you have the URLs.
If you still need to have the images locally, Save them to disk and store those local File URLs in your database.

Related

Right way to manage application generated files

tl;dr
In my node.js application I create pdf documents. What is the best/right way to save them? Right now I use node.js fileserver and shell.js to do it.
I am working on a node.js web application to manage apartments and tenants for learning purpose and on some point I create PDF Documents that I want to save under a path
/documents/building_name/apartment_name/tenant_name/year/example.pfd
Now if the user wants to change the building, apartment or tenant name via an http PUT request I change the database but also the want to change the path.
Well both works but I can't write good tests for these functions.
Now a friend told me that it's a bad practice to save documents on a file server and I better should use BLOB.
On the other side google doesn't really agree on using blobs
So what is the right way to save documents?
Thanks
Amit
You should first define a source of truth. Unless you're legally obliged to keep copies of those files and they are not being accessed very often, I wouldn't even bother storing those at all and just generate them upon request.
If not, keep the DB clean, blobs will make it huge. Put them into cold storage (again assuming they are not being accessed too frequently) without those paths. If the paths are reliant on often changing information, that can't be performant for neither the file server nor your system.
Instead store a revision number in your DB that the file can be found under and limit the path structure to information that rarely change.
Like {building}/{apartment}/{tenant}_{revision}.pfd
That - depending on your backup structure - will allow you to time-travel if necessary and doesn't force a re-index all the time.
Note: I don't know too much about your use case.

Suggestion About Creating a Web Database Application

I am new in web developers world. I have created a website (www.formsify.in) on Wordpress all by learning on internet. I know the basics of coding and programming languages, etc. and the interest so I learn quickly. Now my objective is to let users search and download documents (.pdf). The way I dl it now is by uploading the documents in Media and use buttons to navigate to the page which displays documents in a tabular form.
Now, this works if the documents are less in numbers. But I know the number of documents will increase and it will be very difficult for me to deal with uploading them one by one and creating tables all the time. So I thought to create
(1). Database of documents
(2). Uploading interface
(3). User interface
I want suggestions whether I am thinking in the right direction or can there be a better way to accomplish this. And if this is a right way to do
What database shall I use keeping in mind that I the documents to be stored online so the database should be online.
How should I go about creating the uploading interface keeping in mind that I am not a code-geek.
How shall I be going to design the user interface.
I know these are very wide and open questions. Also because stalwarts here will give me a non-commercial, non-biased view. I just need directions. I was able to create a decent website (as per my standards) when I didn't know much the only thing drove me to do that was that I was hellbent. I will be thankful for any suggestions.
Thanks,
.farhan
So, basically, you should have 2 tables:
User
Upload
User hold an ID and whatever information you want to have on the user and the upload table holds a unique ID, a user ID (of the uploader) and a path to the document
This way, you can select the uploads (add filters if needed) and you can construct the tables and views using the database results
The uploading is a simple html form that will send the file to a php script that will upload the file to a folder (rename it as well) and insert the new path in the dB.
The user interface just needs to hold a bit of html, with a form element and an action to a php script to handle the upload.
You can find the upload script on w3schools, just add the mysql insert to the database.

can i create a database without mysql on raspberry pi

I've got a raspberry pi with raspbian and all I've done is installed apache2 and created a small web site i want to create a database.
is this possible without using mysql or other database software. i want to use .JS or a text based database
I want to be able to save the contact details in a text format.
can someone point me in the right direction a simple example would be appreciated all online research wants mysql etc
all i want is a simple example as in enter name and submit i want that name to be logged so if name entered again it will say welcome back once i know this mechanism i can add all the other fields. The reason i want this format is so i can see the list that I'm creating.
i just can't get to grips with mysql I've spent months trying to understand mysql but its just not going in so want to simplify the database to minimal workings so i can complete my site. I know .Js isn't so secure but its a demo so security not important at this point any help appreciated
It would be possible to use JSON for your data storage. It will be a key-value storage. On each page view you will have to load the entire file into memory and parse it. From then on it is possible to loop it to search data or get data from a key. This requires no extra software just PHP with Apache.
How to:
Build an array, use json_encode to create the JSON and save it using file_put_contents(). Remebmer to save the whole array and not just the newly added element.
This is not a relative database but might do the trick if you build an intelligent system with cookie's to store an ID that is associated with a user.
Alternative you could use serialize() instead of json;
If you don't mind to use different way of storing data you can use either Google App Engine or mongolab or other cloud based databases

Is it bad to store images as Data URIs in a database BLOB?

I'm creating a mobile app that views articles. These articles are just simple html with a couple of images each. I am currently storing everything in a database. Later, I will need to save the articles locally to the device in an easy format. For this reason, I have opted to store the Base64 images within the database, using a Data URI Scheme (look here for info http://en.wikipedia.org/wiki/Data_URI_scheme).
My question is: is it okay to store this much data in one database entry? I have a table that is ONLY for these large records, with article meta data tables that point to these. Would it be better if I used TEXT fields, rather than BLOBs?
If it helps, I am using MySQL with the InnoDB engine.
Avoiding using the db to store images is a good practice, keeping the images in the db not only slows down your db performance it also increases it size and backups, if you are using cloud service then there is also the cost issue.
Use S3 or Azure for this purpose and have only the url of the images in your db.Files may be uploaded directly to to the storage service reducing load on your db server. The only thing left to do is for your mobile application to connect both this services(db and the Images service),i found this web tool to manage my mobile app db because it connect to my Images cloud service which is Azure but i think they also support Amazon S3.
Another option would be to store images in something like:
Amazon S3
and then just have a field in your database that stored the url for each image.
As long as you dont have a DB as big as facebook or similar it should be fine.
It is best to store just the path to the image and the image themselves in a folder.
hope that helps
You could also look into Azure Blob Storage. I've been using it and it's working very well.

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.