ผมลองนำ vba code จากเวบนี้ไปลองส่งไฟล์งานด้วยการใช้ผ่าน msaccess2013 แต่ไม่สามารถส่งได้ ตัวอย่าง code
Sub Line01()
Dim URL As String
Dim sToken As String
Dim sFilepath As String
Dim nFile As Integer
Dim baBuffer() As Byte
Dim ssPostData1 As String
Dim ssPostData2 As String
Dim ssPostData3 As String
Dim Messagelength As Integer
Dim arr1() As Byte
Dim arr2() As Byte
Dim arr3() As Byte
Dim arr4() As Byte
Const STR_BOUNDARY As String = "------------------------058b4eeb7d99b4f6"
sToken = "" ' <<< Token
URL = "
https://notify-api.line.me/api/notify"
sFilepath = "d:\img7.jpg"
sFileName = GetFilenameFromPath(sFilepath)
ssPostData1 = vbCrLf & _
"--" & STR_BOUNDARY & vbCrLf & _
"Content-Disposition: form-data; name=" & """message""" & vbCrLf & vbCrLf
arr1 = StrConv(ssPostData1, vbFromUnicode)
arr2 = (" ")
ssPostData2 = vbCrLf & _
"--" & STR_BOUNDARY & vbCrLf & _
"Content-Disposition: form-data; name=" & """imageFile""" & "; filename=" & sFileName & vbCrLf & _
"Content-Type: image/jpng" & vbCrLf & vbCrLf
arr3 = StrConv(ssPostData2, vbFromUnicode)
nFile = FreeFile
Open sFilepath For Binary Access Read As nFile
If LOF(nFile) > 0 Then
ReDim baBuffer(0 To LOF(nFile) - 1) As Byte
Get nFile, , baBuffer
imagear = baBuffer
End If
Close nFile
arr4 = StrConv(vbCrLf & "--" & STR_BOUNDARY & "--" & vbCrLf, vbFromUnicode)
Dim arraytotal As Long
Dim sendarray() As Byte
arraytotal = UBound(arr1) + UBound(arr2) + UBound(arr3) + UBound(imagear) + UBound(arr4) + 4
ReDim sendarray(arraytotal)
For I = 0 To UBound(arr1)
sendarray(I) = arr1(I)
Next
For I = 0 To UBound(arr2)
sendarray(UBound(arr1) + I + 1) = arr2(I)
Next
For I = 0 To UBound(arr3)
sendarray(UBound(arr1) + UBound(arr2) + I + 2) = arr3(I)
Next
For I = 0 To UBound(imagear)
sendarray(UBound(arr1) + UBound(arr2) + UBound(arr3) + I + 3) = imagear(I)
Next
For I = 0 To UBound(arr4)
sendarray(UBound(arr1) + UBound(arr2) + UBound(arr3) + UBound(imagear) + I + 4) = arr4(I)
Next
With CreateObject("Microsoft.XMLHTTP")
.Open "POST", URL, 0
.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & STR_BOUNDARY
.setRequestHeader "Authorization", "Bearer " & sToken
.send sndar(sendarray)
Debug.Print .responseText
End With
เกิด error ที่บรรทัดนี้ข้อความว่า type mismatch ครับแก้ไขอย่างไรครับ
arraytotal = UBound(arr1) + UBound(arr2) + UBound(arr3) + UBound(imagear) + UBound(arr4) + 4
End Sub