VBA: Datei Upload mit http: POST
25.10.2025 17:10:14
Robert Hoch
schönen Gruß an alle; ich hoffe jemand hat einen Hinweis wo ich ansetzen kann.
Problembeschreibung:
• VBA aus Excel (das muss auch so bleiben) und funktioniert anscheinend ja auch (zumindest bei Anderen im Forum, die mit den Lösungen zufrieden waren)
• seit einigen Tagen versuche ich eine Datei per POST hochzuladen
• habe bereits Vieles versucht und Foren, sowie den API-Provider durchkämmt
• leider ohne Erfolg
• bekomme immer eine Fehlermeldung: "error": "internal_error"
• Manuelles Upload und automatische Auswertung mit Excel-VBA (GET) klappt.
• mein Test-VBA Code und Beispiel-Codes vom Provider in CURL + Python anbei (hier veröffentlichte API-key ist natürlich fake)
• bitte keine Hinweise wie, ich sollte es mit einer anderen Programmiersprache versuchen
Vielen Dank im Voraus
Robert
https://developer.millionverifier.com/#operation/bulk-upload
Beispiel: Python-Code
import requests
url = "https://bulkapi.millionverifier.com/bulkapi/v2/upload?key=your-api-key"
files=[
('file_contents',('filename',open('path/to/file','rb'),'text/plain'))
]
response = requests.request("POST", url, files=files)
print(response.text)
Beispiel: CURL-Code
curl --location --request POST 'https://bulkapi.millionverifier.com/bulkapi/v2/upload?key=your-api-key' \
--form 'file_contents=@"path/to/file"'
---------------------------------------------------------------------------------------------------------------------------------------------------------------
VBA-Code
Public Sub UploadFile()
Dim sFormData, bFormData
Dim d As String, DestURL As String, fileName As String, filePath As String, FieldName As String, content As String
Dim ado As Object
Const Boundary As String = "---------------------------0123456789012"
' Const DEALID As String = "9822"
FieldName = "file"
DestURL = "https://bulkapi.millionverifier.com/bulkapi/v2/upload?key=xxxxxxxxxxxxxxxxxxx"
fileName = "Email_Bulk-Verifikation.txt"
content = "text/plain"
filePath = "E:\" + fileName
Dim File, FILESIZE
Set ado = CreateObject("ADODB.Stream")
ado.Type = 1 'binary
ado.Open
ado.LoadFromFile filePath
ado.Position = 0
FILESIZE = ado.Size
File = ado.Read
ado.Close
Set ado = CreateObject("ADODB.Stream")
d = "--" + Boundary + vbCrLf
' d = d + "Content-Disposition: form-data; name=""deal_id""" & vbCrLf & vbCrLf
d = d + "Content-Disposition: form-data" & vbCrLf
' d = d + DEALID & vbCrLf
d = d + "--" + Boundary + vbCrLf
d = d + "Content-Disposition: form-data; name=""" + FieldName + """;"
d = d + " filename=""" + fileName + """" + vbCrLf
d = d + "Content-Type: " & content + vbCrLf + vbCrLf
ado.Type = 1 'binary
ado.Open
ado.Write ToBytes(d)
ado.Write File
ado.Write ToBytes(vbCrLf + "--" + Boundary + "--" + vbCrLf)
ado.Position = 0
With CreateObject("MSXML2.ServerXMLHTTP")
.Open "POST", DestURL, False
' .setRequestHeader "Content-Type", "multipart/form-data; boundary=" & Boundary
.SetRequestHeader "Content-Type", "text/plain; boundary=" & Boundary
.send ado.Read
Debug.Print .responseText
End With
End Sub
Function ToBytes(str As String) As Variant
Dim ado As Object
Set ado = CreateObject("ADODB.Stream")
ado.Open
ado.Type = 2 ' text
ado.Charset = "_autodetect"
ado.WriteText str
ado.Position = 0
ado.Type = 1
ToBytes = ado.Read
ado.Close
End Function
Anzeige