Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADODB.Stream error '800a0bbc' - write to file failed.

Status
Not open for further replies.

wvdba

IS-IT--Management
Jun 3, 2008
465
0
0
US
Hi.
I have this page that is supposed to display a jpg image from a db on an intranet page (which works fine). I have been asked to let a user to save this jpg image save on his/her local machine when the image is displayed on the page. I used a piece of code that tsuji had posted a while back in response to a user. But, i'm getting this error when i used the code:
ADODB.Stream error '800a0bbc'
Write to file failed.
/custom_apps/property_items_list2.asp, line 111
line 111 is: .savetofile slocal,2 'save-create-overwrite
any ideas how I can correct this?
thanks.
 
No ideas. You need to post your code (not just the single line that is getting the error), and a link to the post that you got tsuji's code from would help too.

Silly question; why can't the user right-click the image and select "Save As..."?
 
there are hundreds of images based on a page that gets the BLOB (binary large object) from an oracle DB and displays it on a page. here's the code:
Code:
surl="[URL unfurl="true"]http://10.xxx.xxx.xxx/offimage/imagedisplay_int.asp?bookid=77863"[/URL]
slocal="c:\a\fleet\" & first_name & "_" & middle_name & "_" & last_name & ".jpg"
'   on error resume next
set oxmlhttp=createobject("msxml2.xmlhttp")
if err.number<>0 then
    wscript.echo "msxml2.xmlhttp not installed. Operation aborted."
    wscript.quit(1)
end if
with oxmlhttp
    .open "get",surl,false
    .send
end with 

if err.number<>0 then
    wscript.echo "Resource unavailable for varied reasons. Operation aborted."
    set oxmlhttp=nothing : wscript.quit(2)
end if

set ostream = createobject("adodb.stream")
with ostream
    .type=1    'binary
    .mode=3    'read-write
    .open
    .write oxmlhttp.responsebody
    .savetofile slocal,2    'save-create-overwrite
    .close
end with
if err.number<>0 then
    wscript.echo "You need ado2.5 up. Operation aborted"
else
    wscript.echo "Done!" & vbcrlf & "Source : " & surl & vbcrlf & "Local : " & slocal
end if
on error goto 0
set ostream=nothing : set oxmlhttp=nothing
 
What type of authentication are you using? If anonymous, then check that IUSR_servername has permission to the folder.
 
the asp page is on the intranet.
the page displays an image.
i want to save the image to my local machine.
just as if i right-clicked.
i'm not sure where to use/set authentication.
thanks.
 
OK, starting to understand. The authentication type is set in IIS by whoever set up the website, but I don't think that's the problem now. ASP executes on a server. The "savetofile" method is being performed by the server, and the location it is saving to (C:\a\fleet\filename.jpg in your sample), would be on the server. If there is no C:\a\fleet folder on the server, you will get an error.

I have not tried doing this from an image from a database, but I have used the method in the link below to allow users to click a hyperlink, get a "Save" dialog, and save a file from my server to wherever they want on their local computer.

 
that's a great suggestion for a save dialog box.
but i'm trying to do this for 1000's of images automatically.
 
You can try saving to a folder on the server that is shared
 
wvdba said:
but i'm trying to do this for 1000's of images automatically.

Never going to happen, not unless all your users are in a fixed environment of Windows with Infernet Exploder, so the browser can run ActieX or initiate a WSH (Windows Script Host) script.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
ok. let's say i don't display the page and the image and just want to write the binary data to a file.
1 - i retrieve the binary data (image) from the database.
2 - how do i write this binary data to a file to be used as an image file?
in asp classic? or vb script?
 
thanks chris.
the code on the link does not write the binary data (image) toto file. it just displays it on the browser. i'm able to do that. i just need the binary data to be written to a .jpg file.
thanks.
 
If you send the binary data with an image/jpeg ContentType header and .jpg|jpeg file extension it will be.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
SOLVED:
here's the code that i used in vbscript that actually workd.
Code:
strCon = 'connection string for database goes here 
Set objConn = WScript.CreateObject("ADODB.Connection")      
     Set objRs = WScript.CreateObject("ADODB.Recordset")
     objConn.Open strCon

sql = "SELECT image_data from images " & _ 
       "where image_object_id between 77863 and 99999" & _ 
         "and active_flag = 'Y' " & _ 
         "and image_object_type = 'OFF_BKG' "  

Set objRs = objConn.Execute(sql) 

if Not objRS.EOF then 
   objRS.MoveFirst
else
   msgbox "no records found"
   wscript.quit
end if 

Do While Not objRS.EOF 
        i = i + 1
        oLOB = objrs.Fields.Item("image_data").Value	 
	SaveBinaryData "c:\a\fleet\photo" & i & objRS.Fields.item("image_data") 
                      &  ".jpg", oLOB
        ' images will be named photo1.jpg, photo2.jpg, photoN.jpg 
        objRS.MoveNext
Loop 
	 
objRS.Close
Set objRS = Nothing
objConn.close
Set objConn = Nothing
msgbox "finished"

' -----------------------------------------------------------

Function SaveBinaryData(FileName, ByteArray)
	Const adTypeBinary = 1
	Const adSaveCreateOverWrite = 2

	'Create Stream object
	Dim BinaryStream
	Set BinaryStream = CreateObject("ADODB.Stream")

	'Specify stream type - we want To save binary data.
	BinaryStream.Type = adTypeBinary

	'Open the stream And write binary data To the object
	BinaryStream.Open
	BinaryStream.Write ByteArray

	'Save binary data To disk
	BinaryStream.SaveToFile FileName, adSaveCreateOverWrite

	BinaryStream.Close
	Set BinaryStream = Nothing
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top