mime-typeを検出するようにしてみた(#56)
This commit is contained in:
@@ -4,6 +4,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Medias {
|
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() {
|
Upload::Upload() {
|
||||||
url_ = "https://upload.twitter.com/1.1/media/upload.json";
|
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";
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
bodyParam_.insert_or_assign("command", "INIT");
|
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,
|
HttpPost::process(_oauth,
|
||||||
[&media](const unsigned int _responseCode, const std::string& _rsv) {
|
[&media](const unsigned int _responseCode, const std::string& _rsv) {
|
||||||
|
|||||||
@@ -4,11 +4,14 @@
|
|||||||
#include <cocoatweet/api/interface/httpPost.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
#include <cocoatweet/api/model/mediaStore.h>
|
#include <cocoatweet/api/model/mediaStore.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Medias {
|
namespace CocoaTweet::API::Medias {
|
||||||
class Upload : public CocoaTweet::API::Interface::HttpPost {
|
class Upload : public CocoaTweet::API::Interface::HttpPost {
|
||||||
private:
|
private:
|
||||||
std::string media_;
|
std::string media_;
|
||||||
|
static const std::map<std::string, std::string> mimeType;
|
||||||
|
;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Upload();
|
Upload();
|
||||||
|
|||||||
Reference in New Issue
Block a user