Results 1 to 3 of 3

Thread: ADO.Stream

  1. #1
    Rob Black Guest

    Default ADO.Stream

    Havn&#039t had to come here in a while!<BR><BR>I&#039m trying to accept a few file uploads butI don&#039t have the luxury of being able to use any COM objects on the server so I am trying to use the ADO (2.5) Stream object to write binary files.<BR><BR>This code get&#039s stuck on the line with "Stream.Write TheImage" With the error (that i used to get when i started ASP&#039ing!):<BR><BR>ADODB.Stream error &#039 800a0bb9&#039 <BR><BR>Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another<BR><BR>Anyway, here is the code (BTW, the code that Response.Writes the "TheImage" var to the browser works fine, i can even copy that from the HTML source and create the file manually.<BR><BR>The FormSize, FormData, Divider etc.. etc.. are just so that I can strip the headers and be left with the file and nothing else.<BR><BR>CODE<BR>&#060;!--METADATA TYPE="typelib"<BR> UUID="00000205-0000-0010-8000-00AA006D2EA4"<BR> NAME="ADODB Type Library"<BR>--&#062;<BR>&#060;%<BR> Dim Stream<BR><BR> Set Stream = Server.CreateObject("ADODB.Stream")<BR> <BR> FormSize = Request.TotalBytes<BR> FormData = Request.BinaryRead(FormSize)<BR> bnCRLF = ChrB(13) & ChrB(10)<BR> Divider = LeftB(FormData, InStrB(FormData, bnCRLF) - 1)<BR> DataStart = InStrB(FormData, bnCRLF & bnCRLF) + 4<BR> DataEnd = InstrB(DataStart + 1, FormData, Divider) - DataStart<BR> <BR> TheImage = MidB(FormData, DataStart, DataEnd)<BR> <BR> Response.Write "&#060;H1&#062;Binary Data Dump&#060;/H2&#062;&#060;PRE&#062;" & VbCrLf<BR> Response.BinaryWrite TheImage<BR> Response.Write "&#060;/PRE&#062;"<BR><BR> Stream.Open<BR> Stream.Type = adTypeBinary<BR> Stream.Write TheImage<BR> Stream.SaveToFile "w:wwwroot
    ob.gif", adSaveCreateOverWrite<BR> Stream.Close<BR> Set Stream = Nothing<BR>%&#062;<BR><BR>Hope someone can help me (please Mr Mitchell!)<BR><BR>Rob.

  2. #2
    Rob Black Guest

    Default RE: ADO.Stream Still Need Help but..

    Just found out some stuff whilst debugging in InterDev.<BR><BR>Looks like Stream.Write is after an array, which i&#039ve just discovered is how VBScript handles binary data:<BR><BR>BinaryArray[1] = 124<BR>BinaryArray[2] = 45<BR>BinaryArray[1245] = 255<BR>BinaryArray[6025] = 160<BR><BR>etc...<BR><BR>Now, i&#039m grabbing the middle portion (the image, no headers) of that data but at the same time making it a string, still binary, but a string all the same. Which, i think, is the bugger.<BR><BR>I&#039ve tried code that will create an array with only the middle bit of the original binary form data but it doesn&#039t work and wouldn&#039t be sutable anyway, since it would have to be a very dynamic array, or be static but huge!<BR><BR>Any ideas (remember, no COM objects :-( ) ??<BR><BR>(I could use perl but 1) i dont know it, 2) I dont have the money for a perl book because i&#039ve spent my book budges on 3 cisco books and 3) the freebie scripts that i&#039ve found have been rather limited.<BR><BR>HELP ME!<BR><BR>

  3. #3
    Rydo Guest

    Default RE: ADO.Stream Still Need Help but..

    &nbsp;<BR>I&#039ve been working on the same problem, and had the same results. Writing a partial binary string to the stream doesn&#039t seem to work.<BR><BR>I found a way around it. It takes up to 3 times the memory the old text-file method takes because you duplicate the data before writing it to disk, but it&#039s much faster because you don&#039t need the binary to string conversion anymore.<BR><BR>Write all of the binary data into a stream, then read it from the stream into a string, or vice versa.<BR><BR>Set st1 = Server.CreateObject("ADODB.Stream")<BR>st1.Open<BR >st1.Type = adTypeBinary<BR>st1.Write Request.BinaryRead(Request.TotalBytes)<BR>st1.Posi tion = 0<BR>rawData = st1.Read(Request.TotalBytes)<BR> <BR>Parse the string, just like you normally would to find the form-data (filename and location of file in the string). Then use that information to do a Streamcopy of the section of the stream holding the file to a second stream and write that stream to disk.<BR><BR>Set st2 = Server.CreateObject("ADODB.Stream")<BR>st2.Open<BR >st2.Type = adTypeBinary<BR>st1.Position = fileStart - 1 &#039 Position stream at start of (0 based, so subtract 1) file data.<BR>st1.CopyTo st2, fileEnd - fileStart &#039 Copy all of the file&#039s data to the second stream<BR>st2.Position = 0<BR>st2.SaveToFile filePath, adSaveCreateOverwrite<BR>st2.Close<BR>Set st2 = Nothing<BR><BR>Do this for all uploaded files, then close the first stream.<BR><BR>st1.Close<BR>Set st1 = Nothing<BR><BR>Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts