mime-typeを検出するようにしてみた(#56)

This commit is contained in:
keita
2021-03-11 14:32:25 +09:00
parent 9d90f01c9f
commit a8aa3173bd
2 changed files with 10 additions and 1 deletions
+7 -1
View File
@@ -4,6 +4,11 @@
#include <iostream>
namespace CocoaTweet::API::Medias {
const std::map<std::string, std::string> Upload::mimeType = {{".jpg", "image/jpeg"},
{".jpeg", "image/jpeg"},
{".png", "image/png"},
{".gif", "image/gif"},
{".mp4", "video/mp4"}};
Upload::Upload() {
url_ = "https://upload.twitter.com/1.1/media/upload.json";
}
@@ -29,7 +34,8 @@ CocoaTweet::API::Model::MediaStore Upload::process(
{
contentType_ = "application/x-www-form-urlencoded";
bodyParam_.insert_or_assign("command", "INIT");
bodyParam_.insert_or_assign("media_type", "image/jpeg");
bodyParam_.insert_or_assign(
"media_type", mimeType.at(std::filesystem::path(media_).extension().string<char>()));
HttpPost::process(_oauth,
[&media](const unsigned int _responseCode, const std::string& _rsv) {
+3
View File
@@ -4,11 +4,14 @@
#include <cocoatweet/api/interface/httpPost.h>
#include <cocoatweet/api/model/mediaStore.h>
#include <string>
#include <filesystem>
namespace CocoaTweet::API::Medias {
class Upload : public CocoaTweet::API::Interface::HttpPost {
private:
std::string media_;
static const std::map<std::string, std::string> mimeType;
;
public:
Upload();