I have registered in a website that supports API and I have tested the CURL command line and it works fine for me
curl --location --request POST "https://api.imgbb.com/1/upload?key=APIKEY" --form "image=iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
this is API information page https://api.imgbb.com/
I have no great knowledge of how to use excel VBA to send an equivalent command line? I am totally new to such stuff and I have searched a lot and can't get how things go on
I have found this link that may be helpful but it is in VB.NET Help with Imgur API and VB.NET - Image POST
** Now I got the solution and I have developed it like that
Sub Test()
Dim v As Double, sPath As String, sAPIKey As String, sBase64 As String, cmd As String
sPath = ThisWorkbook.Path & "\Result.txt"
sAPIKey = "APIKEY"
sBase64 = ConvertFileToBase64(ThisWorkbook.Path & "\Logo.png")
cmd = Replace(Replace("curl --location --request POST ""https://api.imgbb.com/1/upload?key=¤"" --form ""image=$"" -o ", "¤", sAPIKey), "$", sBase64) & sPath
v = Shell(cmd)
Debug.Print cmd & " Completed" & vbCr & "Process " & v
End Sub
Public Function ConvertFileToBase64(strFilePath As String) As String
Const UseBinaryStreamType = 1
Dim streamInput: Set streamInput = CreateObject("ADODB.Stream")
Dim xmlDoc: Set xmlDoc = CreateObject("Microsoft.XMLDOM")
Dim xmlElem: Set xmlElem = xmlDoc.CreateElement("tmp")
streamInput.Open
streamInput.Type = UseBinaryStreamType
streamInput.LoadFromFile strFilePath
xmlElem.DataType = "bin.base64"
xmlElem.NodeTypedValue = streamInput.Read
ConvertFileToBase64 = Replace(xmlElem.Text, vbLf, "")
Set streamInput = Nothing
Set xmlDoc = Nothing
Set xmlElem = Nothing
End Function
This works fine for small sizes but not for the large ones ..example I have a Logo.png and the size is 545KB in size and this fails. While other smaller images uploaded well
I have manually tried it and it failed too. it seems cms window has a limit number of characters allowed so I can't get all the base64 string in the command line