So that i can, upload the JPEG via POST method. (Everything is working except cant find how to convert ImageGadget images into base64 data string)
Code: Select all
InitNetwork()
IncludeFile "libcurl.pbi"; Download https://raw.githubusercontent.com/deseven/pbsamples/master/crossplatform/libcurl/libcurl.pbi
; Upload JPEG via CURL POST method
pictures.s = "data:image/jpeg;base64,"
; JPEG image uploader
Procedure iCurl()
curl = curl_easy_init()
url.s = str2curl("https://imgur.com/upload")
agent.s = str2curl("pbcurl/1.0")
cookie.s = str2curl("agent=purebasic;")
post.s = str2curl("userid=1&preview=" + pictures)
header.s = str2curl("Cache-Control: no-cache")
If curl
curl_easy_setopt(curl,#CURLOPT_URL,@url)
curl_easy_setopt(curl,#CURLOPT_IPRESOLVE,#CURL_IPRESOLVE_V4)
curl_easy_setopt(curl,#CURLOPT_COOKIE,@cookie)
curl_easy_setopt(curl,#CURLOPT_POSTFIELDS,@post)
curl_easy_setopt(curl,#CURLOPT_USERAGENT,@agent)
curl_easy_setopt(curl,#CURLOPT_TIMEOUT,30)
curl_easy_setopt(curl,#CURLOPT_FOLLOWLOCATION,1)
*header = curl_slist_append(0,header)
curl_easy_setopt(curl,#CURLOPT_HTTPHEADER,*header)
curl_easy_setopt(curl,#CURLOPT_WRITEFUNCTION,@curlWriteData())
res = curl_easy_perform(curl)
resData.s = curlGetData()
curl_easy_getinfo(curl,#CURLINFO_RESPONSE_CODE,@resHTTP)
Debug "result: " + Str(res)
If Not res
Debug "HTTP code: " + Str(resHTTP)
Debug "HTTP data: " + #CRLF$ + resData
EndIf
curl_easy_cleanup(curl)
Else
Debug "can't init curl!"
EndIf
EndProcedure
If OpenWindow(0,300,200,300,200,"test",#PB_Window_SystemMenu)
pic1=CreateImage(1,50,50)
pic2=CreateImage(2,100,100)
StartDrawing(ImageOutput(2))
Box(0,0,100,100,#Red)
StopDrawing()
ImageGadget(1,20,20,100,100,pic1)
ButtonGadget(2,20,130,130,25,"Click to switch images")
Repeat
ev=WaitWindowEvent()
If ev=#PB_Event_Gadget And EventGadget()=2
count+1
If count=1
; === HELLO === HERE
; How to make the pic2 as "data:image/jpeg;base64...." ?
;
pictures.s = "data:image/jpeg;base64,"
; === HELLO === HERE
iCurl()
SetGadgetState(1,pic2)
SetGadgetText(2,"Click to clear image")
ElseIf count=2
SetGadgetState(1,0)
EndIf
EndIf
Until ev=#PB_Event_CloseWindow
EndIf