-
Notifications
You must be signed in to change notification settings - Fork 1
/
UploadFileWebserviceFromVB6.vb
62 lines (50 loc) · 1.73 KB
/
UploadFileWebserviceFromVB6.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Public Function getFilename(strFullPath As String) As String
On Error Resume Next
getFilename = Right(strFullPath, Len(strFullPath) - InStrRev(strFullPath, "\"))
End Function
Public Function UpLoadData(strFilename As String, strTargetURL As String, Optional namaFile As String) As String
Dim oHttp As XMLHTTP
Dim strBody As String
Dim aPostData() As Byte
Dim oSignature As String
Dim strResponse As String
Dim nFile As Long
Dim strText As String
On Error GoTo ErrorHandler
nFile = FreeFile
Open strFilename For Binary As #nFile
strText = String(LOF(nFile), " ")
Get #nFile, , strText
Close #nFile
Set oHttp = New XMLHTTP
If namaFile = "" Then
namaFile = getFilename(strFilename)
End If
oHttp.Open "POST", strTargetURL, False
oHttp.setRequestHeader "Content-Type", "multipart/form-data, boundary=AaB03x"
strBody = _
"--AaB03x" & vbCrLf & _
"Content-Disposition: form-data; name=""filename""" & vbCrLf & vbCrLf & _
namaFile & vbCrLf
strBody = strBody & "--AaB03x" & vbCrLf & _
"Content-Disposition: attachment; name=""gambar""; filename=""" & strFilename & """" & vbCrLf & _
"Content-Type: text/plain" & vbCrLf & vbCrLf & _
strText & vbCrLf & _
"--AaB03x--"
aPostData = StrConv(strBody, vbFromUnicode)
oHttp.send aPostData
strResponse = oHttp.responseText
UpLoadData = strResponse
GoTo LastSub
On Error GoTo 0
Exit Function
ErrorHandler:
MsgBox "Error : (" & Err.number & ") " & Err.Description, vbExclamation, App.Title
UpLoadData = "ERROR UPLOAD"
GoTo LastSub
Exit Function
LastSub:
On Error Resume Next
Set oHttp = Nothing
On Error GoTo 0
End Function