SoundCloud桌面应用LibCurl:如何上传文件
SoundCloud Desktop App & LibCurl: How to Upload a File?
我用LibCurl在SoundCloud上上传文件到经过身份验证的用户帐户时遇到了严重的困难。
我已经得到了到目前为止从一组json格式的字符串(感谢通过LibCurl调试回调)得到以下错误消息;'"error_message": "无法上传文件,确定它们是有效的声音文件吗?"?'.
我一直在测试的文件是最简单的形式,由各种daw创建:PCM波,单声道和立体声,不同的长度但短(最多几秒钟-用于快速测试目的),44.1 kHz采样率和16位深度。此外,我可以通过SoundCloud网站上的浏览器上传它们,没有任何抱怨……
谁能看看下面的代码来帮助找出问题?
CURL* handle = curl_easy_init();
curl_slist* headers = nullptr;
curl_httppost* formPost = nullptr;
curl_httppost* lastPtr = nullptr;
curl_easy_setopt (handle, CURLOPT_URL, "https://api.soundcloud.com/tracks.json");
curl_easy_setopt (handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_setopt (handle, CURLOPT_CAINFO, "(absolute path)/cacert.pem");
curl_easy_setopt (handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) -1);
headers = curl_slist_append (headers, "Expect: 100-continue");
headers = curl_slist_append (headers, "Content-type: multipart/form-data");
curl_formadd (&formPost,
&lastPtr,
CURLFORM_COPYNAME, "oauth_token",
CURLFORM_COPYCONTENTS, /*token*/,
CURLFORM_END);
curl_formadd (&formPost,
&lastPtr,
CURLFORM_COPYNAME, "track[asset_data]",
CURLFORM_COPYCONTENTS, "Tone.wav",
CURLFORM_END);
curl_formadd (&formPost,
&lastPtr,
CURLFORM_COPYNAME, "track[title]",
CURLFORM_COPYCONTENTS, "Tone",
CURLFORM_END);
curl_formadd (&formPost,
&lastPtr,
CURLFORM_COPYNAME, "track[sharing]",
CURLFORM_COPYCONTENTS, "public",
CURLFORM_END);
curl_formadd (&formPost,
&lastPtr,
CURLFORM_COPYNAME, "Tone.wav",
CURLFORM_FILE, "C:/440 Hz Tone - 3 Seconds.wav",
CURLFORM_END);
curl_easy_setopt (handle, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt (handle, CURLOPT_HTTPPOST, formPost);
curl_easy_setopt (handle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) /* size of file in bytes */);
curl_easy_setopt (handle, CURLOPT_VERBOSE, (long) 1);
curl_easy_setopt (handle, CURLOPT_DEBUGFUNCTION, /*debug function*/);
curl_easy_setopt (handle, CURLOPT_NOPROGRESS, (long) 0);
curl_easy_setopt (handle, CURLOPT_PROGRESSFUNCTION, /*debug progress function*/);
curl_easy_perform (handle);
curl_easy_cleanup (handle);
curl_formfree (formPost);
curl_slist_free_all (headers);
作为新手,我不理解变量"track[asset_data]"应该包含本地文件路径。下面是固定的代码;
CURL* handle = curl_easy_init();
curl_slist* headers = nullptr;
curl_httppost* formPost = nullptr;
curl_httppost* lastPtr = nullptr;
curl_easy_setopt (handle, CURLOPT_URL, "https://api.soundcloud.com/tracks.json");
curl_easy_setopt (handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_setopt (handle, CURLOPT_CAINFO, "(absolute path)/cacert.pem");
curl_easy_setopt (handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) -1);
headers = curl_slist_append (headers, "Expect: 100-continue");
headers = curl_slist_append (headers, "Content-type: multipart/form-data");
curl_formadd (&formPost,
&lastPtr,
CURLFORM_COPYNAME, "oauth_token",
CURLFORM_COPYCONTENTS, /*token*/,
CURLFORM_END);
curl_formadd (&formPost,
&lastPtr,
CURLFORM_COPYNAME, "track[title]",
CURLFORM_COPYCONTENTS, "Tone",
CURLFORM_END);
curl_formadd (&formPost,
&lastPtr,
CURLFORM_COPYNAME, "track[sharing]",
CURLFORM_COPYCONTENTS, "public",
CURLFORM_END);
curl_formadd (&formPost,
&lastPtr,
CURLFORM_COPYNAME, "track[asset_data]",
CURLFORM_FILE, "C:/440 Hz Tone - 3 Seconds.wav",
CURLFORM_END);
curl_easy_setopt (handle, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt (handle, CURLOPT_HTTPPOST, formPost);
curl_easy_setopt (handle, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t) /* size of file in bytes */);
curl_easy_setopt (handle, CURLOPT_VERBOSE, (long) 1);
curl_easy_setopt (handle, CURLOPT_DEBUGFUNCTION, /*debug function*/);
curl_easy_setopt (handle, CURLOPT_NOPROGRESS, (long) 0);
curl_easy_setopt (handle, CURLOPT_PROGRESSFUNCTION, /*debug progress function*/);
curl_easy_perform (handle);
curl_easy_cleanup (handle);
curl_formfree (formPost);
curl_slist_free_all (headers);
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 我无法在 Flutter 桌面嵌入项目(在 Visual Studio 上)中创建 obj 文件
- 在窗口或桌面窗口中单击文件
- 对桌面进行了更改.ini使用批处理文件,但文件夹图标不会更改
- 无法创建或打开 *.VS 2015 中的 VC.db 文件(桌面快速版)更新 3RC
- 如何获取哪些快捷方式和文件在桌面等文件夹路径中突出显示
- 学习C++.正在将文件写入桌面.无处可寻
- 使用winapi从桌面用c++打开一个文件
- 在桌面上创建文件 (C++)
- 将文件拖放到C++WinForms中的桌面图标上
- 将多个文件输出/输入到桌面
- visual如何在C++中将文件保存到桌面
- 您可以将C++桌面应用程序中的输入数据或其他类型的数据存储在文本文件之外的文件中吗
- 具有桌面.ini和即时刷新功能的自定义文件夹图标
- 使用fopen在桌面上打开文件时,权限被拒绝
- SoundCloud桌面应用LibCurl:如何上传文件
- 如何在桌面上的文件夹中创建文本文件
- 默认将文件写入桌面
- 在哪里放置要与Windows用户的桌面设置一起漫游的用户数据文件?