This commit is contained in:
+10
-6
@@ -12,6 +12,9 @@ using std::string;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
using Managers::FileManager;
|
||||
using Models::UploadForm;
|
||||
|
||||
using namespace cpr;
|
||||
|
||||
namespace Syncers
|
||||
@@ -20,22 +23,23 @@ namespace Syncers
|
||||
Upload::Upload(string filePath)
|
||||
{
|
||||
this->songPath = filePath;
|
||||
this->fMgr = Managers::FileManager(songPath);
|
||||
this->fMgr = FileManager(songPath);
|
||||
}
|
||||
Upload::Upload(UploadForm formData)
|
||||
{
|
||||
this->url = formData.url;
|
||||
this->songPath = formData.filePath;
|
||||
}
|
||||
|
||||
|
||||
void Upload::uploadSong()
|
||||
{
|
||||
configureSongDemo();
|
||||
|
||||
string url = apiUrl + ":" + std::to_string(port) + apiEndPoint;
|
||||
|
||||
try
|
||||
{
|
||||
auto r = cpr::Post(cpr::Url{url},
|
||||
cpr::Multipart{{"key", "small value"},
|
||||
{"file", cpr::File{songPath}}});
|
||||
cout << r.text << std::endl;
|
||||
cout << r.status_code<< std::endl;
|
||||
|
||||
cout<<"Success"<<endl;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include"Managers/FileManager.h"
|
||||
#include"Models/Song.h"
|
||||
#include"Models/UploadForm.h"
|
||||
|
||||
|
||||
namespace Syncers
|
||||
@@ -16,6 +17,7 @@ namespace Syncers
|
||||
public:
|
||||
Upload();
|
||||
Upload(std::string);
|
||||
Upload(Models::UploadForm);
|
||||
|
||||
void uploadSong();
|
||||
|
||||
@@ -25,6 +27,7 @@ namespace Syncers
|
||||
std::string apiUrl{"http://192.168.1.3"};
|
||||
std::string apiEndPoint{"/api/song/data"};
|
||||
std::string songPath;
|
||||
std::string url;
|
||||
int port{9349};
|
||||
|
||||
void configureSongDemo();
|
||||
|
||||
Reference in New Issue
Block a user