Store Retrieve Files (picture/mp3/excel/doc etc) to/from SQL Server
This is a technical article for new bees on how to upload/update/download files (picture/mp3/excel/doc) into sql server database..
https://www.youtube.com/user/masterke...
Closed Caption:
hi friends so in this video and what we
would be looking at is a very general
requirement that we have of saving blobs
for this blog that is Mandy large
objects then in sequence of our database
we work bc is actually normal a
beautiful ascii type
I mean we would ask you techno if we
want to save data in binary format that
is let's see you have some files there
is one excel file a JPG files of picture
and an mp3 song that I want to save into
my sequel server and there is some
application which actually allows users
to upload such files and saves them to
my database at the same time it allows
the user to update that value
I mean and then at the end maybe also
download such files from the existing
database to some of application Howard
this Peter so that is what we are
looking at today so for a force for this
demo of what i would be showing is a
simple table that i will create of with
the name of file warehouse so this is
the table what I would be doing here is
yeah
ok so i have three columns in this table
or that is an idea identity value file
type file type is actually your xls
files are that is your excel file or
maybe it's not JPG files or your mp3
files and the action fight so if you
notice the important thing to notice is
the file type for the store files is bad
binding and i have given their binary
max you could if if the binary value of
your file is going to be less than
800,000 bite you could actually mention
that if it is below you go to edge
actually mentioned that value but since
you expect a value of any length you can
give it max by which any size of the
file can be saved into your database so
let's say now they will be inserting a
file of type xls x into our data in on
this table currently this table is not
having anything so now what we do is I
go to my fight and we were deceiving 351
excel file a GP g5 and mp3 file so
let me see this excess fire
with the help of open rowset in this is
our 24 min for a taco their taxes with
this open row said the command for the
for saving I mean this file is will be
is saving a single not so with this
command we can save this data into my
table and yeah so that data if you look
at the table was saved but this is
nothing but binary which you is in the
body for man to complete data is has
been serialized I mean broken into the
binary format and then saved into my
table next I will save the picture they
will you all love this movie i'm a big
fan of this movie even just amazing so
next we've saved this picture as well
into our doubles
done and lastly I would be saving of the
beautiful song from Pink Floyd into my
database
this will take some time because it's
not yet dead i mean the size of the mp3
was how much
let's see aight Wars it was kind of 19.7
mb so that file is saved into my
database now if I query i have the data
oops we just made one mistake so
presented made this mistake so just
updating this value and it's now we are
good so we have the three files stored
into my doubles the next thing this is
storing now how I didn't leave it back
so all these three files i would like to
retrieve it back so for that forgiving
that advantage few prerequisites
I mean again I use this equals only to
drive it back and what I'll do is I'll
retrieve it back and put it into my
output folder
ok so let's see how we can do before
that first thing that you do is ok let
me just check the space of mine table
good good and pleasant so now if I first
to take this configuration of your
sequel server that is something only
automation procedures since I'll be
using oily connections so basically for
retrieving the data you need that option
to be enabled so just be careful and
check that first and and if you see this
one I'm talking about
so it i have enabled it on my server but
if it is not enabled on your server be
here be careful and enable that to
enable if you just push experience cool
configure and put the name and say one
little later in PA of conflict value to
1 you do it like this but running and
then again reconfigure your server so
this will this is first thing the second
thing is for driving it
what I is EDD i'll be using the oily
automation process procedures and now
this is the complete for that you need
to air retrieve the data and let's look
at it carefully so
now what I what we have here let's see
this is the object object that we are
creating only object and this is the
output part you can see ok let me just
put it
and this is your final part
so five part
right so now what we are trying to do is
we are this is the store file that we
are retrieving restored find from a
house for one this is the gpg on maybe
filetype ok you can actually use file
type is equal to G ok to know we have
picture DP will be saved
should be calling it
that you find this is actually the fight
so now if I execute this sort of
statement what it is doing is it is
where we are pulling in the jpg file
with this statement and putting it in
the variable file which is of vanity
type again but in bandung max and the
output part where we want to save the
file with the name and then we are
creating and a Leo stream object which
is $OPERAND of only automation one of
the Holy or Commission procedures its
objects object open is the object now we
when the object is created we are
opening methods or opening the matter
writing the fighting the value into the
file and then pushing it i think the
value of the five and then pushing it in
the output part we're saving it in the
output part includes enclosing the
method and destroying the final objects
this is all that is happening so if we
go and secured this currently if you see
sorry if you see there's nothing in the
output now returning back and executing
this if i go and check
I have the picture does that picture
looks the same
yeah I that's okay
yeah it does so I pulled a picture from
my database now I want to pull the rest
of the two files ex-husband
so what is the I pulling all the mp3
file
you can put a different name i'll just
say that you'll save with the value of
them in the fire bc ok let me see
yeah I have the mp3 as well does it run
or is it character
yeah I've does it sounds as beautiful as
always and beautiful song
okay yeah it does play
and does play so my head database is
good
next is I'm also calling . xl5 i named
it one two three
I'm pulling back my xfis let's put all
the truth
yeah because it is what it was
so what all the three files now from my
database i have stored and related back
now my question last thing is in this
video is if I wish to up
I mean update update the file and how
would you do it
so where I mean file type is maybe a
different pic 4 10 will
I want to upload a different picture so
maybe this one the pulse
this picture instead of the tendon so I
go ahead and
okay I will
were not prepared to spend this is again
the same command so I'm just trying to
update the value with the help of P
sequence of updated that in my table
anyways have been looking at the table i
will hardly be able to identify so again
let me just download the value and see
if that value is
ok if that matches not yeah if you look
at me going to the output yeah it does
the new pic with the name is that of the
pink floyd's pause so we are good so
that was a very simple requirement i
mean i think in india is just
implementing this on the website or the
darkest side you will have to create
some are some components and then
implemented but in using this NT sequins
with the sequins pretty simple lemon if
you're uploading you just have a very
simple a sequel commands this will do
the complete uploading off your fight we
just have to feed the pot to this sequel
and it's it's done for you and for that
i have shown you her to upload a file
and then get it back downloaded as well
with the help of oily automation
procedures and then also to update the
file which has been uploaded so that was
it friends at this it's really really
good to share these informations and
have it on with all of you open is
really useful to you thank you
Video Length: 15:28
Uploaded By: Keshav Singh
Published: 3/30/2012
View Count: 55,003