.NET to Delphi 7



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



.



Relevant Pages

  • HttpWebrequest Upload Of (image) Binary file.
    ... When i upload a binary file ... private static string GetMultipartBoundary() ... byteArray = br.ReadBytesnumBytes); ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Convert byte array to string
    ... I need to convert a byte array to a string in order to upload a binary file ... with an httpWebRequest. ...
    (microsoft.public.dotnet.languages.csharp)
  • Convert byte array to string
    ... I need to convert a byte array to a string in order to upload a binary file ... with an httpWebRequest. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Http post
    ... Now if you were for example to build a string out of these 3 things ... Two separate HTTP Post request are required to complete the upload ... The example you sent me works fine and the authentication id can be ... perhaps just simple text string with an attachment (in binary format) ...
    (microsoft.public.fox.programmer.exchange)
  • Re: RFD: How To Recognize Bad Javascript Code v0.3
    ... the current Windows beta; ... the string is empty in 3.0.4. ... overwritten in the filesystem as it would happen during an upload. ...
    (comp.lang.javascript)