.NET to Delphi 7
- From: "Bob_?" <ng1@xxxxxxxxxxxx>
- Date: Thu, 22 Sep 2005 02:38:36 GMT
I'm trying to upload a binary file via HTTP to a ASP.NET application on the
server. Using Indy HTTP I've used
* reqContent := TStringStream.Create(binFileName)
....to create the request stream but the receiving app can't read it. They
sent me .NET code for uploading the file that works, but I'm having trouble
converting it to Delphi. Can someone take a look and help me create the
stream for the upload with Indy HTTP. I'm not good at reading .NET.
Thanks, -Bob
Delphi 7
(hope this is not too big for this NG)
----
Public Sub UploadFileInBinary(ByVal localFile As String, ByVal uploadUrl As
String)
'// Retrieve request stream
Dim reqStream As Stream
Dim req As HttpWebRequest
req = WebRequest.Create(uploadUrl)
req.Method = "POST"
req.AllowWriteStreamBuffering = True
req.Timeout = 200000000
reqStream = req.GetRequestStream()
' // Open the local file
Dim rdr As FileStream
'localFile = arr(0)
rdr = New FileStream(localFile, FileMode.Open)
'// Allocate byte buffer to hold file contents
Dim indata(4096) As Byte
'// loop through the local file reading each data block
'// and writing to the request stream buffer
Dim bytesRead As Integer
bytesRead = rdr.Read(indata, 0, indata.Length)
While (bytesRead > 0)
reqStream.Write(indata, 0, bytesRead)
bytesRead = rdr.Read(indata, 0, indata.Length)
End While
rdr.Close()
'httpRes = req.GetResponse()
'Writing the response onto the file
'
reqStream.Close()
req.GetResponse()
' // Read response back from the page.
Dim httpRes As HttpWebResponse = CType(req.GetResponse(),
HttpWebResponse)
Dim stmReceive As Stream = httpRes.GetResponseStream()
Dim readStream As New StreamReader(stmReceive)
Response.Write(readStream.ReadToEnd())
req.close()
End Sub
.
- Follow-Ups:
- Re: .NET to Delphi 7
- From: Rob Kennedy
- Re: .NET to Delphi 7
- Prev by Date: Need ADOExpress for Delphi 5 Pro
- Next by Date: Re: .NET to Delphi 7
- Previous by thread: Need ADOExpress for Delphi 5 Pro
- Next by thread: Re: .NET to Delphi 7
- Index(es):
Relevant Pages
|