Upload functionality implemented

This commit is contained in:
amazing-username
2019-03-20 21:01:16 -04:00
parent 1ebc61389b
commit e8f2bbcb48
10 changed files with 66 additions and 18 deletions
+2
View File
@@ -1,6 +1,7 @@
#include<iostream>
#include<string>
#include"Syncers/Download.h"
#include"Syncers/Upload.h"
#include"Managers/FileManager.h"
@@ -10,6 +11,7 @@ using std::endl;
using std::string;
using Managers::FileManager;
using Syncers::Download;
using Syncers::Upload;
string songPath;
+2 -1
View File
@@ -41,7 +41,6 @@ namespace Managers
fileBuffer = new char [fileBufferLength];
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
// read data as a block:
is.read (fileBuffer,fileBufferLength);
if (is)
@@ -62,4 +61,6 @@ namespace Managers
{
return fileBuffer;
}
int FileManager::retrieveFileBufferLength() const { return fileBufferLength; }
}
+1
View File
@@ -15,6 +15,7 @@ namespace Managers
void modifyFilePath(std::string);
char* retrieveFileBuffer() const;
int retrieveFileBufferLength() const;
private:
void readFile();
-3
View File
@@ -3,9 +3,6 @@
#include<string>
#include<nlohmann/json.hpp>
using json = nlohmann::json;
namespace Models
{
+4 -1
View File
@@ -1,3 +1,6 @@
#include"Download.h"
Download::Download() { }
namespace Syncers
{
Download::Download() { }
}
+1 -1
View File
@@ -10,7 +10,7 @@ namespace Syncers
public:
Download();
private:
}
};
}
#endif
+17 -10
View File
@@ -26,20 +26,28 @@ namespace Syncers
void Upload::uploadSong()
{
configureSong();
json jObj = serializeObject();
printJsonData(jObj);
configureSongDemo();
std::string url = apiUrl + apiEndPoint;
string url = apiUrl + ":" + std::to_string(port) + apiEndPoint;
auto r = cpr::Post(cpr::Url{url},
cpr::Multipart{{"key", "file"},
{"value", cpr::File{songPath}}});
cout << r.text << std::endl;
try
{
auto r = cpr::Post(cpr::Url{url},
cpr::Multipart{{"key", "small value"},
{"file", cpr::File{songPath}}});
cout << r.text << std::endl;
cout<<"Success"<<endl;
}
catch(std::exception& e)
{
cout<<e.what()<<endl;
}
cout<<"Finished"<<endl;
}
void Upload::configureSong()
void Upload::configureSongDemo()
{
int id = 0;
string title = "What of it?";
@@ -59,7 +67,6 @@ namespace Syncers
this->song.duration = duration;
this->song.songData = fMgr.retrieveFileBuffer();
cout<<*song.songData<<endl;
printSongDetails();
}
void Upload::printSongDetails()
{
+2 -2
View File
@@ -22,12 +22,12 @@ namespace Syncers
private:
Managers::FileManager fMgr;
Models::Song song;
std::string apiUrl{"http://192.168.1.24"};
std::string apiUrl{"http://192.168.1.3"};
std::string apiEndPoint{"/api/song/data"};
std::string songPath;
int port{9349};
void configureSong();
void configureSongDemo();
void printSongDetails();
void printJsonData(nlohmann::json);