summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/curl_wrapper.hpp6
-rw-r--r--include/mastodonpp.hpp5
-rw-r--r--src/curl_wrapper.cpp10
3 files changed, 16 insertions, 5 deletions
diff --git a/include/curl_wrapper.hpp b/include/curl_wrapper.hpp
index 8523057..44f3b0d 100644
--- a/include/curl_wrapper.hpp
+++ b/include/curl_wrapper.hpp
@@ -297,9 +297,9 @@ private:
/*!
* @brief Add `*curl_mimepart` to `*curl_mime`.
*
- * @param mime Initialized `*curl_mime`.
- * @param name Name of the field.
- * @param data Data of the field, or \@filename.
+ * @param mime Initialized `*curl_mime`. @param name Name of the field.
+ * @param data Data of the field. If it begins with <tt>`\@file:<tt>, the
+ * rest of the ergument is treated as a filename.
*
* @since 0.1.1
*/
diff --git a/include/mastodonpp.hpp b/include/mastodonpp.hpp
index 9d00369..a696eac 100644
--- a/include/mastodonpp.hpp
+++ b/include/mastodonpp.hpp
@@ -69,7 +69,10 @@
*
* @subsection input Input
*
- * All text input is expected to be UTF-8.
+ * * All text input is expected to be UTF-8.
+ *
+ * * To send a file, use “<tt>\@file:</tt>” followed by the file name as value
+ * in the @link mastodonpp::parametermap parametermap@endlink.
*
* @section exceptions Exceptions
*
diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp
index 4853628..047b799 100644
--- a/src/curl_wrapper.cpp
+++ b/src/curl_wrapper.cpp
@@ -354,7 +354,15 @@ void CURLWrapper::add_mime_part(curl_mime *mime,
throw CURLException{code, "Could not build HTTP form."};
}
- code = curl_mime_data(part, data.data(), CURL_ZERO_TERMINATED);
+ if (data.substr(0, 6) == "@file:")
+ {
+ const string_view filename{data.substr(6)};
+ code = curl_mime_filedata(part, filename.data());
+ }
+ else
+ {
+ code = curl_mime_data(part, data.data(), CURL_ZERO_TERMINATED);
+ }
if (code != CURLE_OK)
{
throw CURLException{code, "Could not build HTTP form."};