Stream vs Raw Bytes
I'm hoping someone can help me figure out what the pros and cons ar开发者_如何学JAVAe of each method for passing files around.
The workflow would be something like:
- Save the File to DB
- Read the file from the DB
- Display the file on a webpage
Files are primary images but there maybe some video. Should i be working with the raw bytes in this scenario or use the stream object?
What are the benefits of a stream over raw bytes?
Streams will perform better for large files since not all of it needs to be read into memory at one time (depending on the type of stream of course).
Although there are certainly reasons to store files in a database, generally speaking I would recommend against it. It makes it more difficult to backup your database (larger file means more time to backup and restore), more difficult to view the files outside of your application (can occasionally be very useful, especially when debugging), and can be significantly more expensive since it will take up additional bandwidth, processor, memory, and storage.
精彩评论