|
Subject:
|
download data ("image") from SQL database problems
|
|
Posted By:
|
dcleslie
|
Post Date:
|
8/28/2006 2:41:08 PM
|
Hi, I posted this in wrong forum so I'm reposting it here - hopefully someone can help?
I am using motobit to download/upload applications. I'm uploading the file as am "image" in SQL Server 2000 but when I go to download, it gives me a bunch of gibberish, like it's encoded -
My code: <% strConn = "Provider=SQLOLEDB; " strConn = strConn & "Data Source=PHSSQLWEBRPD2; " strConn = strConn & "Initial Catalog=OPRS; " strConn = strConn & "User Id=OPRS; " strConn = strConn & "Password=webshare"
Set Conn = Server.CreateObject("ADODB.Connection") Conn.ConnectionString = strConn Conn.Open %> <% set RSIDB = conn.Execute("select * from DCL5.PanelUpload") Response.ContentType ="application/octet-stream"
Response.binarywrite RSIDB("data") %> Any ideas? I'm fairly new to all of this, so I'm embarrassed that it may be something basic...
thank you! -DC
|
|
Reply By:
|
dparsons
|
Reply Date:
|
8/29/2006 7:27:44 AM
|
Is the field you are trying to display the correct field?
Also try this:
Dim byReader byReader = Response.BinaryRead(rsidb("data")) response.binarywrite(byReader)
Also, from your post in the SQL forum the endcoding is actually the bits of the stream converted into the corrosponding characters (nearest I can tell) and, it looks like, its a PDF file. "The one language all programmers understand is profanity."
|
|
Reply By:
|
dcleslie
|
Reply Date:
|
8/29/2006 10:22:13 AM
|
Thank you but.. it's giving me this error: Microsoft VBScript runtime error '800a01b6' Object doesn't support this property or method: 'Response.BinaryRead' /idb/download.asp, line 17
(line 17 being the binaryread part of your suggested code).
It is a pdf file that I uploaded into the database. That's the admin side which functions great. The user side needs to download the pdf file, or open it at least, that's this page that's giving me trouble..
Any other ideas? Thanks so much for your time!
|
|
Reply By:
|
dparsons
|
Reply Date:
|
8/29/2006 10:40:40 AM
|
Im sorry, it has been a very long time since i have done any hardcore ASP programming, the reason you got that error was because BinaryRead is part of the Request object, not the respone object.
However, on second thought, that should only be used when posting data from a form and then returning it to the user so lets try this instead.
Remove the lines Dim byReader byReader = Response.BinaryRead(rsidb("data"))
Add/Modify this: Response.Expires = 0 Response.Buffer = TRUE Response.Clear Response.ContentType ="application/octet-stream"
Response.BinaryWrite(rsidb("Data"))
hth
"The one language all programmers understand is profanity."
|
|
Reply By:
|
dcleslie
|
Reply Date:
|
8/29/2006 10:45:25 AM
|
Hmm.. i'm getting this now.. but it opens in an asp document, not a web browser..
%PDF-1.4 %âãÏÓ 6 0 obj<> endobj xref 6 9 0000000016 00000 n 0000000609 00000 n 0000000476 00000 n 0000000685 00000 n 0000000812 00000 n 0000000896 00000 n 0000001162 00000 n 0000001352 00000 n 0000001573 00000 n trailer <<45af1f68c535c24149655e40161ad09b><9a164094c9f5464bb13590dec7fd38d0>]>> startxref 0 %%EOF 8 0 obj<>stream xÚb```c``Ò`
|
|
Reply By:
|
dparsons
|
Reply Date:
|
8/29/2006 10:55:44 AM
|
ok, try this (but make sure you are pulling down a PDF file)
Response.ContentType = "application/pdf"
hth
"The one language all programmers understand is profanity."
|
|
Reply By:
|
dcleslie
|
Reply Date:
|
8/29/2006 10:59:25 AM
|
it worked! you're genius! I owe you a beer, or a coffee, or my firstborn! Thank you!
quick question - any idea how i could fix this so it will download any other file such as a word file? some of the will be word files as well as pdf... don't know if there's a somewhat simple way to do that?
again, thank you!!! 
|
|
Reply By:
|
dparsons
|
Reply Date:
|
8/29/2006 12:30:02 PM
|
Here is the thing, the application/octet-stream is kind of like the "fail safe" content type.
For example, I only use it when i am trying to push down an RTF file from my database, all other times I use the proper content type; the reason i told you to use the octet-stream is because your original post said you were pushing down applications, in which case I think .exe files, and you should use the octet-stream.
What you have to do is either: A) Depending on how your uploading component works, you may be able to get the content type of the file your uploading by doing something similar to this: file.ContentType, if you can capture that place that value in your database and then set your content type dynamically as you pull down your file. e.g. Response.ContentType = rsidb("contenttype")
B) Setup a case statement on the upload side to capture the file extension and, based on extension, place that into the database. (.doc files get application/vnd.ms-word, pdf gets application/pdf, etc)
In .NET I am able to capture the ContentType of any file sent through an HtmlInputFile control and save that directly to my database so there is no guess work, since you are using Classic asp, i think you may be limited to what your particular Component can do.
(in any case you should be able to loop through the component and check for the contenttype, check your documentation from motobit)
Ill take a Corona with a Lemon, thank you very much!
hth.
"The one language all programmers understand is profanity."
|
|
Reply By:
|
dcleslie
|
Reply Date:
|
8/29/2006 1:04:34 PM
|
wow... okay, see this is what learning ASP on my own gets me.. lots of holes in my learning, but you have given me a lot to look up and learn so I'll be doing that!
thanks again for all of your help.. i tried squeezing in the corona but it almost fried my keyboard ;)
|
|
Reply By:
|
dparsons
|
Reply Date:
|
8/29/2006 1:10:52 PM
|
Here is a listing of most of the common content types:
http://www.topxml.com/asp/response_object_property_contenttype.asp
"The one language all programmers understand is profanity."
|