Issue with Uploading .zip File Using libcurl in Harbour API Patch Request

134 views
Skip to first unread message

Atul

unread,
Mar 5, 2025, 6:04:33 AMMar 5
to Harbour Users
Hello everyone,

I am using libcurl.dll in my accounting software to make API calls. I recently created a new utility that uses ApiPost to create a file on Google Drive and ApiPatch to upload data.

However, when I use the following code block, the content is not uploaded properly. The issue seems to be that the .zip file contains non-readable characters (between ASCII 0 to ASCII 31), which prevents the full content from being uploaded.

Code that fails to upload properly:
   curl_easy_setopt(::curl, HB_CURLOPT_URL, ::apiurl)
   curl_easy_setopt(::curl, HB_CURLOPT_CUSTOMREQUEST, "PATCH")
   curl_easy_setopt(::curl, HB_CURLOPT_POSTFIELDS, ContentStr)
   curl_easy_setopt(::curl, HB_CURLOPT_SSL_VERIFYPEER, .F.)
   curl_easy_setopt(::curl, HB_CURLOPT_SSL_VERIFYHOST, .F.)
   curl_easy_setopt(::curl, HB_CURLOPT_HTTPHEADER, ::Headers)
   curl_easy_setopt(::curl, HB_CURLOPT_DL_BUFF_SETUP)
   ret := curl_easy_perform(::curl)
   Result := curl_easy_dl_buff_get(::curl)

Code that works properly using RUN(cCommand):

cMetadata := '{ "name": "' + JustFName(cFilePath) + '", "mimeType": "application/zip"}'

cBoundary := "boundary123456789"

cFileData := GetFileContent( cFilePath )

cMultipart  := "--" + cBoundary + CHR(13)+CHR(10)
cMultipart += "Content-Type: application/json; charset=UTF-8" + CHR(13)+CHR(10)+CHR(13)+CHR(10)
cMultipart += cMetadata + CHR(13)+CHR(10)
cMultipart += "--" + cBoundary + CHR(13)+CHR(10)
cMultipart += "Content-Type: application/zip" + CHR(13)+CHR(10)+CHR(13)+CHR(10)
cMultipart += cFileData + CHR(13)+CHR(10)
cMultipart += "--" + cBoundary + "--" + CHR(13)+CHR(10)

cTempFile := "multipart_body.tmp"
WriteFileContent( cMultipart, cTempFile )

cUrl := "https://www.googleapis.com/upload/drive/v3/files/" + cFileId + "?uploadType=multipart"

cCommand := 'curl -X PATCH "' + cUrl + '" ' + ;
            '-H "Authorization: Bearer ' + cAccessToken + '" ' + ;
            '-H "Content-Type: multipart/related; boundary=' + cBoundary + '" ' + ;
            '--data-binary "@' + cTempFile + '"'

Run ( cCommand )

When I use the following code block, my software hangs:  
curl_easy_setopt(::curl, HB_CURLOPT_POSTFIELDSIZE, LEN(ContentStr))

Kindly guide how can I make curl_easy_setopt() code runable and I can get uploaded data properly.

Zastava EFI

unread,
Mar 9, 2025, 1:41:33 PMMar 9
to harbou...@googlegroups.com
Can You send all code ?

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-users/4ddd134d-18f7-447f-995d-4aa73f9c46den%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages