Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,148,876 members, 7,802,816 topics. Date: Friday, 19 April 2024 at 10:29 PM |
Nairaland Forum / Science/Technology / Programming / Converting Picture To Byte Array(blob) And Back To Picture (7288 Views)
"Love At First Byte"! Your Story / Using 2-dimensional Array In C++ / Complete Array Of Countries And Nigerian States [open Source] (2) (3) (4)
Converting Picture To Byte Array(blob) And Back To Picture by cyberbob(m): 10:36am On Oct 23, 2008 |
am writing a project but am having problem in convert images to byte array and storing in a database and retrieving the byte array from the database and displaying the image using java can you help please |
Re: Converting Picture To Byte Array(blob) And Back To Picture by logica(m): 11:21am On Oct 23, 2008 |
maybe if u can be specific and mention the exact problem u r having, i might be able 2 make suggestions. also what rdbms r u using? |
Re: Converting Picture To Byte Array(blob) And Back To Picture by Seun(m): 11:26am On Oct 23, 2008 |
I think it's a good idea not to store images in a database. Why not just store the filename in the database? |
Re: Converting Picture To Byte Array(blob) And Back To Picture by logica(m): 11:41am On Oct 23, 2008 |
i really don't think u have enough info about the app 2 know it's a bad idea 2 store images in a db. |
Re: Converting Picture To Byte Array(blob) And Back To Picture by javarules(m): 3:54pm On Oct 23, 2008 |
I dont usually store images in db too, I store path names, well researching for you, will get back |
Re: Converting Picture To Byte Array(blob) And Back To Picture by Seun(m): 5:38pm On Oct 23, 2008 |
i really don't think u have enough info about the app 2 know it's a bad idea 2 store images in a db.Let's hope he gives us further details about his application, but it's a reasonable assumption |
Re: Converting Picture To Byte Array(blob) And Back To Picture by logica(m): 6:16pm On Oct 23, 2008 |
it is advantageous 2 store a file as an object in cases where u want 2 perform SQL operations involving the file such as selecting all records fitting a filter like the size of the file or containing a particular string/pattern, or even enforcing a constraint. it will be tedious if the file is stored on the file system. it might also provide some form of security as no likely dangerous files are introduced to the file system. |
Re: Converting Picture To Byte Array(blob) And Back To Picture by candylips(m): 9:50pm On Oct 23, 2008 |
cyberbob: Which db are you using you might be trying to store more than the maximum allowed byte size in the blob |
Re: Converting Picture To Byte Array(blob) And Back To Picture by ade2kay(m): 11:32am On Oct 24, 2008 |
google.com |
Re: Converting Picture To Byte Array(blob) And Back To Picture by Seun(m): 12:21pm On Oct 24, 2008 |
logica: SQL operations don't work on files. They work on tables and fields. such as selecting all records fitting a filter like the size of the fileYou can store the file size in the database, so you can SELECT size FROM files WHERE name="topsecret.doc" or containing a particular string/patternIf your data is pure text, this makes some sense. But let's face it, the .txt files are not very common and can usually be broken down into a more structured form. Common file types include .doc, .zip, .pdf, .jpg, .gif, .wmv, .avi are binary files, and you can't search them without converting them to text first. or even enforcing a constraint.This is vague. The devil is in the details! it might also provide some form of security as no likely dangerous files are introduced to the file system.Come on. This is a very long shot. If a file is that dangerous I don't want it in my database either. You have tried, but in real life files (especially images) should be stored in a special folder on disk. |
Re: Converting Picture To Byte Array(blob) And Back To Picture by logica(m): 2:10pm On Oct 24, 2008 |
"SQL operations don't work on files. They work on tables and fields" sql operations do work on files stored as BLOBs which is a field in the intended table isn't it? and what essentially is a BLOB if not just a sequence of bytes? u can perform string operations on these. i don't get your point here, as you seem to agree with the point i raised. File size i already thot about storing the file size in the db, but that is still replication of detail/duplicity. u r storing the same information about the same entity 2ce, as opposed to a file stored as a BLOB, where the size of the file is simply the length of the BLOB - LEN(imagine_file). Contraint the size of file allowed for example. i know u will say this can be enforced before trying to store the file, but the database enforcement is more difficult to get around. Security a file stored in a db is benign and not likely to cause any harm (it is simply a sequence of bytes like i said earlier). now imagine a hypothetical exploit with images for instance (not sure if any have been discovered, but i can bet they do exist). an image file that has been modified to take advantage of this hypothetical exploit cannot do much if stored in a db table, than if stored in the file system where it is possible to perform an execute operation or some other trigger condition/operation might occur. that u don't want it in ur db is not the issue here after all it would have made its way 2 ur file system anyway, but there in the db it is harmless. |
Re: Converting Picture To Byte Array(blob) And Back To Picture by xanadu: 10:33pm On Oct 24, 2008 |
Just to add some web info to this very interesting debate (bold emphasis mine): Should I store images in the database or the filesystem? The above culled from here: http://databases.aspfaq.com/database/should-i-store-images-in-the-database-or-the-filesystem.html |
Re: Converting Picture To Byte Array(blob) And Back To Picture by logica(m): 5:30pm On Oct 25, 2008 |
great points xanadu. but here is a good read: http://research.microsoft.com/research/pubs/view.aspx?msr_tr_id=MSR-TR-2006-45 Application designers often face the question of whether to store large objects in a filesystem or in a database. Often this decision is made for application design simplicity. Sometimes, performance measurements are also used. This paper looks at the question of fragmentation – one of the operational issues that can affect the performance and/or manageability of the system as deployed long term. As expected from the common wisdom, objects smaller than 256K are best stored in a database while objects larger than 1M are best stored in the filesystem. Between 256K and 1M, the read:write ratio and rate of object overwrite or replacement are important factors. We used the notion of “storage age” or number of object overwrites as way of normalizing wall clock time. Storage age allows our results or similar such results to be applied across a number of read:write ratios and object replacement rates. u will also find a link to a PDF file detailing the tests: ftp://ftp.research.microsoft.com/pub/tr/TR-2006-45.pdf from the foregoing, on the issue of fragmentation it seems it is best 2 store images as blobs except of course the images we r dealing with here r ultra-high resolution and therefore extremely huge. u know this discussion just led me to the discovery of Firebird. has anybody tried it? it apparently stores files as blobs much faster than the file can be stored on the file-system. not sure how it compares overall to MySQL but it's also open-source. |
Re: Converting Picture To Byte Array(blob) And Back To Picture by biggjoe(m): 8:58pm On Nov 03, 2008 |
For the past 2 weeks or so that i have been toying with image upload, this debate has left me more confused than any other webdesign decision I had to make. I fancy saving to file and writing details to database but please people, When I update a file from a form, will the new file DELETE the old one in the process or will it just add one more file in the directory? |
Re: Converting Picture To Byte Array(blob) And Back To Picture by logica(m): 9:09am On Nov 04, 2008 |
i believe that's a detail left 4 u 2 implement in ur code in the procedure that writes the file. |
Re: Converting Picture To Byte Array(blob) And Back To Picture by biggjoe(m): 7:35pm On Nov 07, 2008 |
@logica, why not help with the implementation of that procedure. |
Re: Converting Picture To Byte Array(blob) And Back To Picture by logica(m): 1:46pm On Nov 08, 2008 |
sorry i don't have the time, but it's easy enough: i believe java allows u 2 check the existence of a file in the file-system: http://www.roseindia.net/java/beginners/file-directory-exists.shtml . so, in the same procedure (method) that u use in writing the file to the file-system, it could be done using a loop that if the file or copies of it already exist, u simply rename new copies of a file sequentially e.g if the file in question has the name "somefile.doc", new copies of the file can be called "somefile01.doc", "somefile02.doc", etc. i'm sorry if all i said is of no use 2 u. |
Re: Converting Picture To Byte Array(blob) And Back To Picture by yawatide(f): 6:16pm On Nov 08, 2008 |
hmmm, upon all the big grammar, theories and arguments, this thread never finish. You sure say d poster still dey follow una so? Okay, back to my ROM (Read Only Mode, aka fly on the wall) mode |
Re: Converting Picture To Byte Array(blob) And Back To Picture by javadoctor(m): 11:02pm On Apr 23, 2013 |
First of all,if you re building an application in jsr 316 where images can be handled by the Icon interface,you wouldn't need a byte []array.but if its web based,u would need a byte array.an ejb class should persist the image in bytes to the db,to retrieve it on view you wil require a servlet using the image Id from the page request to get the image in byte array and the servletoutputstream object will be written to be viewed. You should understand dat this is a deserializing /serializing process, |
(1) (Reply)
Uber Vs Taxify - Which Do You Prefer? / Javascript In Pidgin!!! / Programming Videos And Books For FREE
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 65 |