Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: How to upload file to sql database without using multipart/form method


Message #1 by "Siew Lien" <sl.chin@f...> on Mon, 21 Oct 2002 08:52:07 +0800
Hi,

I need to upload a file from a physical location at the server which i know the exact location to the SQL server database, but i dun
need user to select a path from the form.

how can i do this? most of the example that i get from internet are using form uploader which the user need to choose the location
from the form. If i need this to be transparent to the user. and just put in the physical path of the file.. could i do this with
form uploader ?

As well, how can i download to the file content to server's physical path from the database ? and rename the file as different file
name ?

thanks in advance for your help ..

cheers ..


regards,
siewlien

Message #2 by "Ken Schaefer" <ken@a...> on Mon, 21 Oct 2002 16:12:41 +1000
The form based method is for uploading a file from the *user's* computer to
the server.

If you want to move a file from the server to the database, why not use ADO?

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Siew Lien" <sl.chin@f...>
Subject: [asp_web_howto] How to upload file to sql database without using
multipart/form method


: I need to upload a file from a physical location at the server which i
know
: the exact location to the SQL server database, but i dun need user to
select
: a path from the form.
:
: how can i do this? most of the example that i get from internet are using
: form uploader which the user need to choose the location from the form.
: If i need this to be transparent to the user. and just put in the physical
: path of the file.. could i do this with form uploader ?
:
: As well, how can i download to the file content to server's physical path
from the database ? and rename the file as different file name ?
:
: thanks in advance for your help ..
:
: cheers ..
:
:
: regards,
: siewlien
:
:
:
: ---
:
: Improve your web design skills with these new books from Glasshaus.
:
: Usable Web Menus
: http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
: r-20
: Constructing Accessible Web Sites
: http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
: r-20
: Practical JavaScript for the Usable Web
: http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
: r-20

Message #3 by "Siew Lien" <sl.chin@f...> on Mon, 21 Oct 2002 14:30:33 +0800
Hi,

Do you mean that we can use the normal ADO method to save the File content
as image to the SQL server database
and later retrieve it from the database to other physical location ?

Thanks ..

regs,
siew lien


----- Original Message -----
From: "Ken Schaefer" <ken@a...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Monday, October 21, 2002 02:12 PM
Subject: [asp_web_howto] Re: How to upload file to sql database without
using multipart/form method


> The form based method is for uploading a file from the *user's* computer
to
> the server.
>
> If you want to move a file from the server to the database, why not use
ADO?
>
> Cheers
> Ken
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> From: "Siew Lien" <sl.chin@f...>
> Subject: [asp_web_howto] How to upload file to sql database without using
> multipart/form method
>
>
> : I need to upload a file from a physical location at the server which i
> know
> : the exact location to the SQL server database, but i dun need user to
> select
> : a path from the form.
> :
> : how can i do this? most of the example that i get from internet are
using
> : form uploader which the user need to choose the location from the form.
> : If i need this to be transparent to the user. and just put in the
physical
> : path of the file.. could i do this with form uploader ?
> :
> : As well, how can i download to the file content to server's physical
path
> from the database ? and rename the file as different file name ?
> :
> : thanks in advance for your help ..
> :
> : cheers ..
> :
> :
> : regards,
> : siewlien
> :
> :
> :
> : ---
> :
> : Improve your web design skills with these new books from Glasshaus.
> :
> : Usable Web Menus
> : http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> : r-20
> : Constructing Accessible Web Sites
> : http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> : r-20
> : Practical JavaScript for the Usable Web
> : http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> : r-20
>
>
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> r-20
> Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20
> Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20
>

Message #4 by "Ken Schaefer" <ken@a...> on Tue, 22 Oct 2002 13:03:38 +1000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Siew Lien" <sl.chin@f...>
Subject: [asp_web_howto] Re: How to upload file to sql database without
using multipart/form method


: Do you mean that we can use the normal ADO method to save the File content
: as image to the SQL server database
: and later retrieve it from the database to other physical location ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Yes.

Look at ADO Stream Object's .LoadFromFile and .SaveToFile methods.
http://msdn.microsoft.com/library/?url=/library/en-us/ado270/htm/mdobjstream
.asp?frame=true

Cheers
Ken

Message #5 by "Siew Lien" <sl.chin@f...> on Fri, 25 Oct 2002 08:58:13 +0800
Hi,

I am using can use the following code to upload a file content to database
and load download to the directory..
by using the LoadFromFile method. (I m using VB program as testing)
I am now facing a problem whereby if the location of my current file is
reside in different file server.
My file is located at Server A, whereas my SQL database is located at Server
B

How do get the location of the path and upload it to database ?

Function UploadFileContentToDB()
    Dim a As New ADODB.Stream
    Dim b As New ADODB.Connection
    Dim rs As New ADODB.Recordset

    a.Open
    a.Type = adTypeBinary
    a.LoadFromFile "e:\temp\fisforcd.txt"

    b.Open "dbTest", "sa", ""
    rs.Open "tblTest", b, adOpenStatic, adLockOptimistic
    rs.AddNew
    rs.Fields("bin").Value = a.Read
    rs.Update

End Function

Function WriteToFile()
    Dim b As New ADODB.Connection
    Dim rs As New ADODB.Recordset

    b.Open "dbTest", "sa", ""
    rs.Open "SELECT * FROM tblTest", b, adOpenStatic, adLockOptimistic
    rs.MoveLast
    Dim a As New ADODB.Stream
    a.Open
    a.Type = adTypeBinary
    a.Write rs.Fields("bin").Value
    a.SaveToFile "c:\temp.txt", adSaveCreateNotExist

End Function


Please help.. thanks ...

Regards,
Siew Lien

----- Original Message -----
From: "Ken Schaefer" <ken@a...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Tuesday, October 22, 2002 11:03 AM
Subject: [asp_web_howto] Re: How to upload file to sql database without
using multipart/form method


> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> From: "Siew Lien" <sl.chin@f...>
> Subject: [asp_web_howto] Re: How to upload file to sql database without
> using multipart/form method
>
>
> : Do you mean that we can use the normal ADO method to save the File
content
> : as image to the SQL server database
> : and later retrieve it from the database to other physical location ?
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Yes.
>
> Look at ADO Stream Object's .LoadFromFile and .SaveToFile methods.
>
http://msdn.microsoft.com/library/?url=/library/en-us/ado270/htm/mdobjstream
> .asp?frame=true
>
> Cheers
> Ken
>
>
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> r-20
> Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20
> Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20
>

Message #6 by "Ken Schaefer" <ken@a...> on Fri, 25 Oct 2002 12:29:05 +1000
If you run the script on ServerA, then you can access ServerB (SQL Server)
using ADO. ADO talks to the underlying provider which is capable of
connecting to the SQL Server using named pipes or TCP/IP. You just need to
specify the location in the connection string.

If you run the Script on ServerB then:
--- You'll need to use UNC paths, because mapped drive letters are only
mapped for the logged on user, ie connect to \\serverA\share\file.ext

--- Make sure that the user context in which the code is being run has
permissions to the remote resource (eg local accounts can not be assigned
permissions to remote resources, you need to use domain accounts instead, or
you need to setup delegation etc)

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Siew Lien" <sl.chin@f...>
Subject: [asp_web_howto] Re: How to upload file to sql database without
using multipart/form method


:
: Hi,
:
: I am using can use the following code to upload a file content to database
: and load download to the directory..
: by using the LoadFromFile method. (I m using VB program as testing)
: I am now facing a problem whereby if the location of my current file is
: reside in different file server.
: My file is located at Server A, whereas my SQL database is located at
Server
: B
:
: How do get the location of the path and upload it to database ?
:
: Function UploadFileContentToDB()
:     Dim a As New ADODB.Stream
:     Dim b As New ADODB.Connection
:     Dim rs As New ADODB.Recordset
:
:     a.Open
:     a.Type = adTypeBinary
:     a.LoadFromFile "e:\temp\fisforcd.txt"
:
:     b.Open "dbTest", "sa", ""
:     rs.Open "tblTest", b, adOpenStatic, adLockOptimistic
:     rs.AddNew
:     rs.Fields("bin").Value = a.Read
:     rs.Update
:
: End Function
:
: Function WriteToFile()
:     Dim b As New ADODB.Connection
:     Dim rs As New ADODB.Recordset
:
:     b.Open "dbTest", "sa", ""
:     rs.Open "SELECT * FROM tblTest", b, adOpenStatic, adLockOptimistic
:     rs.MoveLast
:     Dim a As New ADODB.Stream
:     a.Open
:     a.Type = adTypeBinary
:     a.Write rs.Fields("bin").Value
:     a.SaveToFile "c:\temp.txt", adSaveCreateNotExist
:
: End Function
:
:
: Please help.. thanks ...
:
: Regards,
: Siew Lien
:
: ----- Original Message -----
: From: "Ken Schaefer" <ken@a...>
: To: "ASP Web HowTo" <asp_web_howto@p...>
: Sent: Tuesday, October 22, 2002 11:03 AM
: Subject: [asp_web_howto] Re: How to upload file to sql database without
: using multipart/form method
:
:
: > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: > From: "Siew Lien" <sl.chin@f...>
: > Subject: [asp_web_howto] Re: How to upload file to sql database without
: > using multipart/form method
: >
: >
: > : Do you mean that we can use the normal ADO method to save the File
: content
: > : as image to the SQL server database
: > : and later retrieve it from the database to other physical location ?
: > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: >
: > Yes.
: >
: > Look at ADO Stream Object's .LoadFromFile and .SaveToFile methods.
: >
:
http://msdn.microsoft.com/library/?url=/library/en-us/ado270/htm/mdobjstream
: > .asp?frame=true
: >
: > Cheers
: > Ken
: >
: >
: >
: > ---
: >
: > Improve your web design skills with these new books from Glasshaus.
: >
: > Usable Web Menus
: > http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
: > r-20
: > Constructing Accessible Web Sites
: > http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
: > r-20
: > Practical JavaScript for the Usable Web
: > http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
: > r-20
: >
:
:
:
: ---
:
: Improve your web design skills with these new books from Glasshaus.
:
: Usable Web Menus
: http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
: r-20
: Constructing Accessible Web Sites
: http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
: r-20
: Practical JavaScript for the Usable Web
: http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
: r-20

Message #7 by "Siew Lien" <sl.chin@f...> on Fri, 25 Oct 2002 14:45:23 +0800
We dont actually share the directory at the File/Document Server.
We are creating the Virtual Path of the Directory at Document Server.


----- Original Message -----
From: "Ken Schaefer" <ken@a...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Friday, October 25, 2002 10:29 AM
Subject: [asp_web_howto] Re: How to upload file to sql database without
using multipart/form method


> If you run the script on ServerA, then you can access ServerB (SQL Server)
> using ADO. ADO talks to the underlying provider which is capable of
> connecting to the SQL Server using named pipes or TCP/IP. You just need to
> specify the location in the connection string.
>
> If you run the Script on ServerB then:
> --- You'll need to use UNC paths, because mapped drive letters are only
> mapped for the logged on user, ie connect to \\serverA\share\file.ext
>
> --- Make sure that the user context in which the code is being run has
> permissions to the remote resource (eg local accounts can not be assigned
> permissions to remote resources, you need to use domain accounts instead,
or
> you need to setup delegation etc)
>
> Cheers
> Ken
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> From: "Siew Lien" <sl.chin@f...>
> Subject: [asp_web_howto] Re: How to upload file to sql database without
> using multipart/form method
>
>
> :
> : Hi,
> :
> : I am using can use the following code to upload a file content to
database
> : and load download to the directory..
> : by using the LoadFromFile method. (I m using VB program as testing)
> : I am now facing a problem whereby if the location of my current file is
> : reside in different file server.
> : My file is located at Server A, whereas my SQL database is located at
> Server
> : B
> :
> : How do get the location of the path and upload it to database ?
> :
> : Function UploadFileContentToDB()
> :     Dim a As New ADODB.Stream
> :     Dim b As New ADODB.Connection
> :     Dim rs As New ADODB.Recordset
> :
> :     a.Open
> :     a.Type = adTypeBinary
> :     a.LoadFromFile "e:\temp\fisforcd.txt"
> :
> :     b.Open "dbTest", "sa", ""
> :     rs.Open "tblTest", b, adOpenStatic, adLockOptimistic
> :     rs.AddNew
> :     rs.Fields("bin").Value = a.Read
> :     rs.Update
> :
> : End Function
> :
> : Function WriteToFile()
> :     Dim b As New ADODB.Connection
> :     Dim rs As New ADODB.Recordset
> :
> :     b.Open "dbTest", "sa", ""
> :     rs.Open "SELECT * FROM tblTest", b, adOpenStatic, adLockOptimistic
> :     rs.MoveLast
> :     Dim a As New ADODB.Stream
> :     a.Open
> :     a.Type = adTypeBinary
> :     a.Write rs.Fields("bin").Value
> :     a.SaveToFile "c:\temp.txt", adSaveCreateNotExist
> :
> : End Function
> :
> :
> : Please help.. thanks ...
> :
> : Regards,
> : Siew Lien
> :
> : ----- Original Message -----
> : From: "Ken Schaefer" <ken@a...>
> : To: "ASP Web HowTo" <asp_web_howto@p...>
> : Sent: Tuesday, October 22, 2002 11:03 AM
> : Subject: [asp_web_howto] Re: How to upload file to sql database without
> : using multipart/form method
> :
> :
> : > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : > From: "Siew Lien" <sl.chin@f...>
> : > Subject: [asp_web_howto] Re: How to upload file to sql database
without
> : > using multipart/form method
> : >
> : >
> : > : Do you mean that we can use the normal ADO method to save the File
> : content
> : > : as image to the SQL server database
> : > : and later retrieve it from the database to other physical location ?
> : > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> : >
> : > Yes.
> : >
> : > Look at ADO Stream Object's .LoadFromFile and .SaveToFile methods.
> : >
> :
>
http://msdn.microsoft.com/library/?url=/library/en-us/ado270/htm/mdobjstream
> : > .asp?frame=true
> : >
> : > Cheers
> : > Ken
> : >
> : >
> : >
> : > ---
> : >
> : > Improve your web design skills with these new books from Glasshaus.
> : >
> : > Usable Web Menus
> : >
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> : > r-20
> : > Constructing Accessible Web Sites
> : >
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> : > r-20
> : > Practical JavaScript for the Usable Web
> : >
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> : > r-20
> : >
> :
> :
> :
> : ---
> :
> : Improve your web design skills with these new books from Glasshaus.
> :
> : Usable Web Menus
> : http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> : r-20
> : Constructing Accessible Web Sites
> : http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> : r-20
> : Practical JavaScript for the Usable Web
> : http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> : r-20
>
>
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> r-20
> Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20
> Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20
>

Message #8 by "Ken Schaefer" <ken@a...> on Fri, 25 Oct 2002 16:58:41 +1000
I don't understand what you are saying.

Which server is running the script?

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Siew Lien" <sl.chin@f...>
Subject: [asp_web_howto] Re: How to upload file to sql database without
using multipart/form method


: We dont actually share the directory at the File/Document Server.
: We are creating the Virtual Path of the Directory at Document Server.
:
:
: ----- Original Message -----
: From: "Ken Schaefer" <ken@a...>
: To: "ASP Web HowTo" <asp_web_howto@p...>
: Sent: Friday, October 25, 2002 10:29 AM
: Subject: [asp_web_howto] Re: How to upload file to sql database without
: using multipart/form method
:
:
: > If you run the script on ServerA, then you can access ServerB (SQL
Server)
: > using ADO. ADO talks to the underlying provider which is capable of
: > connecting to the SQL Server using named pipes or TCP/IP. You just need
to
: > specify the location in the connection string.
: >
: > If you run the Script on ServerB then:
: > --- You'll need to use UNC paths, because mapped drive letters are only
: > mapped for the logged on user, ie connect to \\serverA\share\file.ext
: >
: > --- Make sure that the user context in which the code is being run has
: > permissions to the remote resource (eg local accounts can not be
assigned
: > permissions to remote resources, you need to use domain accounts
instead,
: or
: > you need to setup delegation etc)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  Return to Index