question

ChandrashekarA-0743 avatar image
0 Votes"
ChandrashekarA-0743 asked Bruce-SqlWork answered

How to post a file from vb script to Web Api

I have a Task like below

I have client machine path (i.e., C:/Folder1) in excel office js.
I am passing that path to macro vb and reading files by below code.

In below for each loop myFile is my file object

My Quetion is: how to post the data from macro vb to Web Api?

 Sub LoopThroghEachFile(mySourcePath)
     Dim ShellObject As Object, MyObject As Object, MySource As Object, myFile As Object, dirObject As Object, iCol As Byte
    
     Set ShellObject = CreateObject("Shell.Application")
     Set dirObject = ShellObject.Namespace(mySourcePath)
     Set MyObject = CreateObject("Scripting.FileSystemObject")
     Set MySource = MyObject.GetFolder(mySourcePath)
        
     If iRow = 0 Then
         iRow = 1
     End If
     On Error Resume Next
  
     For Each myFile In MySource.Files
           
     Next
     Set ShellObject = Nothing
     Set dirObject = Nothing
     Set MyObject = Nothing
     Set MySource = Nothing
 End Sub









office-vba-devoffice-scripts-excel-devdotnet-aspnet-core-webapi
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered

You use the xmlhttp object to make the post request

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms759148(v=vs.85)

Typically a file upload is done via a multipart form post. Xmlhttp does not have direct support for form posts, you will need to build the payload.

Spec for multipart post

https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.