I am downloading files with an HTTP Post. The cgi-script sends the files when requested. This little peice of code saves the files as they are sent. The only problem is that when the Put# is used with the variant on the FIRST call and when it is called the second time within the loop, it will PAD 12 bytes of data to the "chunk" when it saves it. I think it has to do with the vtData variant variable being a variant.
These 12 bytes looks like: 1120 0100 D002 0000 0000 0000
I don't want to have to strip these from the file everytime. That would be nonsense...
Does anyone have any different methods of writing chunks of binary files? Thanks in advance...
Aaron
Dim vtData As Variant ' Data variable.
Dim nFileNum As Integer
nFileNum = FreeFile
Kill App.Path & "\" & FileServerList(FileBuffer, 1) 'delete any existing file
Open App.Path & "\" & FileServerList(FileBuffer, 1) For Binary Access Write Lock Read Write As #nFileNum
' Get the first chunk. NOTE: specify a Byte
vtData = Inet2.GetChunk(1024, icByteArray)
Do While LenB(vtData) > 0
Put #nFileNum, , vtData
ProgressBar1.value = (Int((Len(vtData) / CLng(FileServerList(FileBuffer, 6))) * 100)) * 2
lblProgressInfo.Caption = "Current File: " & FileServerList(FileBuffer, 1) & " - Downloaded " & CStr(Len(strText)) & " bytes (" & ProgressBar1.value & "%)"
' Get next chunk.
vtData = Inet2.GetChunk(1024, icByteArray)
Loop
Put #nFileNum, , vtData
Close #nFileNum
These 12 bytes looks like: 1120 0100 D002 0000 0000 0000
I don't want to have to strip these from the file everytime. That would be nonsense...
Does anyone have any different methods of writing chunks of binary files? Thanks in advance...
Aaron
Dim vtData As Variant ' Data variable.
Dim nFileNum As Integer
nFileNum = FreeFile
Kill App.Path & "\" & FileServerList(FileBuffer, 1) 'delete any existing file
Open App.Path & "\" & FileServerList(FileBuffer, 1) For Binary Access Write Lock Read Write As #nFileNum
' Get the first chunk. NOTE: specify a Byte
vtData = Inet2.GetChunk(1024, icByteArray)
Do While LenB(vtData) > 0
Put #nFileNum, , vtData
ProgressBar1.value = (Int((Len(vtData) / CLng(FileServerList(FileBuffer, 6))) * 100)) * 2
lblProgressInfo.Caption = "Current File: " & FileServerList(FileBuffer, 1) & " - Downloaded " & CStr(Len(strText)) & " bytes (" & ProgressBar1.value & "%)"
' Get next chunk.
vtData = Inet2.GetChunk(1024, icByteArray)
Loop
Put #nFileNum, , vtData
Close #nFileNum