Added functionality to upload a song. Need to write parse classes to parse the base API HTTP endpoint, and the source path. #7

This commit is contained in:
amazing-username
2019-06-03 22:29:20 -04:00
parent 56bf7f1900
commit 8230f7b5ff
10 changed files with 215 additions and 12 deletions
+25 -2
View File
@@ -1,4 +1,5 @@
#include<iostream>
#include<exception>
#include<string>
#include<cpr/cpr.h>
@@ -8,6 +9,7 @@
using std::cout;
using std::endl;
using std::exception;
using std::string;
using json = nlohmann::json;
@@ -37,8 +39,8 @@ namespace Syncers
try
{
auto r = cpr::Post(cpr::Url{url},
cpr::Multipart{{"key", "small value"},
{"file", cpr::File{songPath}}});
cpr::Multipart{{"key", "small value"},
{"file", cpr::File{songPath}}});
cout << r.status_code<< std::endl;
cout<<"Success"<<endl;
@@ -50,6 +52,27 @@ namespace Syncers
cout<<"Finished"<<endl;
}
void Upload::uploadSong(const Models::Token token, const std::string songPath)
{
try
{
string auth{token.tokenType};
auth.append(" " + token.accessToken);
auto r = cpr::Post(cpr::Url{""},
cpr::Multipart{{"key", "small value"},
{"file", cpr::File{songPath}}},
cpr::Header{{"authorization", auth}}
);
cout << r.status_code<< std::endl;
}
catch (exception e)
{
auto msg = e.what();
cout<<msg<<endl;
}
cout<<"Finished"<<endl;
}
void Upload::configureSongDemo()
{