Curl 在谷歌硬盘上传请求中使用可恢复选项

Curl 在谷歌硬盘上传请求中使用可恢复选项,curl,google-drive-api,Curl,Google Drive Api,我想上传一个独立于大小的文件。我使用“可恢复”选项。下面的代码适用于文本文件,但当我使用pdf文件或其他扩展名(jpg,7z)时,总是会出现503错误。此外,如果我想通过区块发送,我会收到代码308。 此外,是否可以将用户元数据添加为“key=value” 我发现pdf文件有问题。事实上,我通过文件大小更改了strlen(buffer)以获取信息,如果添加“curl_easy_setopt(curl,CURLOPT_HTTPHEADER,headerList);”就可以了,所以对于最后一个块,我

我想上传一个独立于大小的文件。我使用“可恢复”选项。下面的代码适用于文本文件,但当我使用pdf文件或其他扩展名(jpg,7z)时,总是会出现503错误。此外,如果我想通过区块发送,我会收到代码308。 此外,是否可以将用户元数据添加为“key=value”


我发现pdf文件有问题。事实上,我通过文件大小更改了strlen(buffer)以获取信息,如果添加“curl_easy_setopt(curl,CURLOPT_HTTPHEADER,headerList);”就可以了,所以对于最后一个块,我收到了200 OK
// Get Buffer
pInputName = fopen (FILE_PATH,"rb");
if (pInputName==NULL) {
    perror ("Error opening file");
    return (-1);
}
else
{
    resultat = fseek(pInputName, 0, SEEK_END);
    filesize= (size_t) ftell(pInputName);
    rewind(pInputName);
    buffer = (char *) calloc(filesize+1, sizeof(char));
    resultat = fread (buffer,sizeof(char),filesize,pInputName);
    fclose (pInputName);
}


// GET LOCATION
sprintf_s(tmp, 100, "Authorization: Bearer %s",auth);
headerList = curl_slist_append(headerList, tmp);

curl_easy_reset(curl);
curl_easy_setopt( curl, CURLOPT_URL, "https://www.googleapis.com/upload/drive/v2/files?uploadType=resumable") ;
curl_easy_setopt( curl, CURLOPT_POST, 1 ) ;
curl_easy_setopt( curl, CURLOPT_POSTFIELDS, titre ) ;
curl_easy_setopt( curl, CURLOPT_HEADER, 1 ) ;

sprintf_s(tmp,100,"Content-Length: %d",size_titre);
headerList = curl_slist_append(headerList, tmp);
headerList = curl_slist_append(headerList, "Content-Type: application/json; charset=UTF-8");
headerList = curl_slist_append(headerList, "X-Upload-Content-Type: text/plain");
sprintf_s(tmp,100,"X-Upload-Content-Length: %d",filesize);
headerList = curl_slist_append(headerList, tmp);
curl_easy_setopt( curl, CURLOPT_HTTPHEADER,  headerList) ;

curl_easy_setopt( curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt( curl, CURLOPT_WRITEDATA, &writeMemory);
curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt( curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt( curl, CURLOPT_SSL_VERIFYHOST, 0L);

        curl_easy_perform(curl);

value = getValue(&writeMemory, "Location: ", ',');

// PUT Request
curl_slist_free_all(headerList);
headerList = NULL;
curl_easy_reset(curl);
curl_easy_setopt( curl, CURLOPT_URL, value) ;
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt( curl, CURLOPT_POSTFIELDS, buffer ) ;
curl_easy_setopt( curl, CURLOPT_POSTFIELDSIZE, strlen(buffer) ) ;

sprintf_s(tmp, 100, "Authorization: Bearer %s",auth);
headerList = curl_slist_append(headerList, tmp);
sprintf_s(tmp,100,"Content-Length: %d",filesize);
headerList = curl_slist_append(headerList, tmp);
headerList = curl_slist_append(headerList, "Content-Type: application/pdf");
sprintf_s(tmp, 100, "Content-Range: bytes */%d", filesize);
headerList = curl_slist_append(headerList, tmp);

curl_easy_setopt( curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt( curl, CURLOPT_WRITEDATA, &writeMemoryPut);
curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt( curl, CURLOPT_WRITEHEADER, &writeMemory);
curl_easy_setopt( curl, CURLOPT_HEADERFUNCTION, WriteMemoryCallback);
curl_easy_setopt( curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt( curl, CURLOPT_SSL_VERIFYHOST, 0L);

curl_easy_perform(curl);