0

Everything seems to be working except I get this below error in the WEBAPI:

Unexpected end of MIME multipart stream. MIME multipart message is not complete.

When I upload the same file from postman to the WEBAPI endpoint it works perfectly. Makes me think its a problem with the VB application.

BTW: Not skilled in VB (Inherited Application trying to make it work to upload large files)

Dim fileBytes As Byte() = Nothing
        Dim boundary As String = "---------------------------" + DateTime.Now.Ticks.ToString("x")
        Using binaryReader As New BinaryReader(fileUpload1.PostedFile.InputStream)
            fileBytes = binaryReader.ReadBytes(binaryReader.BaseStream.Length)
            binaryReader.Close()
        End Using
        Dim request As HttpWebRequest =
          WebRequest.Create("http://mylocalhost/api/directory")
        request.Method = "POST"
        request.ContentType = "multipart/form-data; boundary = " + boundary
        request.ContentLength = fileBytes.Length
        request.Accept = "*/*"
        request.AutomaticDecompression = DecompressionMethods.GZip
        request.KeepAlive = True

        Dim newStream As IO.Stream = request.GetRequestStream()
        newStream.Write(fileBytes, 0, fileBytes.Length)
        'newStream.Close()


        Dim response As WebResponse = request.GetResponse()
        ' Display the status.
        Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
        ' Get the stream containing content returned by the server.
        Dim dataStream As IO.Stream = response.GetResponseStream()
        ' Open the stream using a StreamReader for easy access.
        Dim reader As New StreamReader(dataStream)
        ' Read the content.
        Dim responseFromServer As String = reader.ReadToEnd()

        Debug.WriteLine("File uploaded")
        Return True````
 

Camrat
  • 33
  • 7
  • You also need to enclose the actual _content_ with the MIME boundary, see e.g. [this SO question](https://stackoverflow.com/questions/4656287/what-rules-apply-to-mime-boundary). Your code only _specifies_ the boundary you're attempting to use in the header. – Hel O'Ween Mar 08 '22 at 09:10

0 Answers0