Converting Image File to Binary


There was required in one of project couple of months ago, wherein the image files have to be stored/inserted into the database using BizTalk.

Although we know that keeping files on folder location is much better than storing it in Database, we had to implement.

Note: BLOBs(Image files, Video files etc) smaller than 256KB are more efficiently handled by a database,while a filesystem is more efficient for those greater than 1MB. Of course, this will vary between different databases and filesystems.


It seemed to be challenging at the beginning, but was an interesting experience for me and my colleague  Dhiraj Bhavsar.

To achieve this, we came up with a solution of creating a Helper class which will convert the file into binary and later can be used .

Below is a screenshot  of Helper Class, which accepts a file path as input and returns data in bytes and deletes the file.


converting image file to binary





Note: This can used for other types of files also. 

Download Helper Class CodeFileReader - Helper Class to convert file into Bytes

Have composed an article as to how to insert images in SQL, have a look : BizTalk Server 2010: How to Insert Image In SQL Through Orchestration

Download BizTalk Server 2010: How to Insert Image In SQL Through Orchestration Sample 


If you have questions or suggestions, feel free to do in comments section below !!!


Do share if you find this helpful .......
 
                          Knowledge Sharing is Caring !!!!!!



2 Comments

If you have any suggestions or questions or want to share something then please drop a comment

  1. This is great example dude. Thanks for including my contribution!!!

    ReplyDelete
  2. Thanks for sharing the blog, it provide the information how Converting Image File to Binary.

    Image Converter

    ReplyDelete
Previous Post Next Post