Out of Memory - Reading a 80MB file into memory in VB6
I'm getting a VB6 "Out of Memory" error when reading contents from a large file (80MB) into memory to be streamed to a web service using the Microsoft INet Control. The web service only accepts a single "POST" call from the VB6 application to process the entire contents of the file. Below is the code snippet that I am using. The line in red is where I get the "Out of Memory" error. It is happening with "TSO.Read(FileName.Size - 1)". Can anyone help me resolve this issue?
Thanks
-------------------------------------------
Dim FSO As FileSystemObject
Dim TSO As TextStream
Dim FileName As File
Dim strImportFile As String
strImportFile = GetImportFileName() ' gets the import filename
HttpRequestHeader = GetRequestHeader() ' gets the http request header (25 character string)
If Trim(strImportFile) <> vbNullString Then
Set FSO = New FileSystemObject
Set FileName = FSO.GetFile(strImportFile)
Set TSO = FileName.OpenAsTextStream(ForReading, TristateFalse)
'stream the data from the file to a webservice using Microsoft INet Control
m_Inet.Execute , "POST", TSO.Read(FileName.Size - 1), HttpRequestHeader
TSO.Skip FileName.Size
TSO.Close
End If
Set TSO = Nothing
Set FSO = Nothing
-------------------------------------------
Re: Out of Memory - Reading a 80MB file into memory in VB6
Wait until TSO exists on your machine. Then compress it. Then upload it.
Re: Out of Memory - Reading a 80MB file into memory in VB6
I'd think you'd be better off reading the file in chunks, and feeding the data to your upload routine as the server takes it. Not sure if the inet control would be the most appropriate for that though.
Re: Out of Memory - Reading a 80MB file into memory in VB6
If the web service only accepts a single POST command, splitting up is not an option.
I'd first see what is causing the problem:
Split up the troublesome line into two seperate commands. First read the file into a string variable
Code:
Dim strInFile as String
strInFile = TSO.Read(FileName.Size - 1)
then try to send the string
Code:
m_Inet.Execute , "POST", strInFile, HttpRequestHeader
See which one fails.
Re: Out of Memory - Reading a 80MB file into memory in VB6
Quote:
Originally Posted by
WoF
If the web service only accepts a single POST command, splitting up is not an option.
While it is true that there'd only be a single POST command, there would be many packets of data for a file of the size in question.
The Winsock control has a SendProgress event. I'd think this could be used to collect additional chucks of data from the file to be sent. I've not used the inet control, so I don't know if it offers something of this sort.
The POST command includes the total length of the data being sent, so the server would be expecting more if only part of it were sent. It's been awhile since I had to deal with this, so I'd probably use a packet sniffer to see what handshaking goes on between client and server during an upload.