Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJari Koopman
Python Web Development Techdegree Graduate 29,349 PointsImages in database
I am building an iOS app which is using a database. I'm pretty new in databases and I have no idea how to put an image in to a database. Can someone please help me out?
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Jari,
If you search Google there are some good resources that come up. However, for all that I found on "How?" I found just as many as to "Why?"
I'm by no means an expert on Databases, but even my first thought when I read your question was "are you sure you want to do that?" Personally, I think it would be easier and more efficient to include the images in your code files and just use the database to reference the url of the image.
I've read through some of the "How" threads and it seems like much more work and not as stable or reliable as just using the urls in the DB and storing the images on the server.
Let me know how it goes. Keep Coding! :)
Dave Moses
301 PointsStoring images in a database is normally not recommended as it will bloat the database size and retrieval can be slow. The recommended way is to store the image in another location and reference it in the database. For example, you may store the image on another server, and in your database table, reference the location with an identifier of some sort (preferably a primary key/clustered index for speed).
Jari Koopman
Python Web Development Techdegree Graduate 29,349 PointsJari Koopman
Python Web Development Techdegree Graduate 29,349 PointsHi Jason,
I red through some of the sites and came to the same conclusion as you did, storing url's in db is way easier. So that is what I have done. Thanks for your answer, I came a lot further!