Upload functionality implemented
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.8.7)
|
||||||
|
project(IcarusDownloadManager)
|
||||||
|
|
||||||
|
if(NOT ${CMAKE_VERSION} LESS 3.2)
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
else()
|
||||||
|
message(STATUS "Checking compiler flags for C++11 support.")
|
||||||
|
# Set C++11 support flags for various compilers
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||||
|
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||||
|
if(COMPILER_SUPPORTS_CXX11)
|
||||||
|
message(STATUS "C++11 is supported.")
|
||||||
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
endif()
|
||||||
|
elseif(COMPILER_SUPPORTS_CXX0X)
|
||||||
|
message(STATUS "C++0x is supported.")
|
||||||
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++")
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(cpr)
|
||||||
|
|
||||||
|
add_executable(icd src/Main.cpp src/Managers/FileManager.h src/Managers/FileManager.cpp src/Syncers/Upload.h src/Syncers/Upload.cpp
|
||||||
|
src/Syncers/Download.h src/Syncers/Download.cpp src/Models/Song.h)
|
||||||
|
target_link_libraries(icd ${CPR_LIBRARIES})
|
||||||
|
include_directories(${CPR_INCLUDE_DIRS} ${JSON_INCLUDE_DIRS} src/)
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include<string>
|
#include<string>
|
||||||
|
|
||||||
|
#include"Syncers/Download.h"
|
||||||
#include"Syncers/Upload.h"
|
#include"Syncers/Upload.h"
|
||||||
#include"Managers/FileManager.h"
|
#include"Managers/FileManager.h"
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ using std::endl;
|
|||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
using Managers::FileManager;
|
using Managers::FileManager;
|
||||||
|
using Syncers::Download;
|
||||||
using Syncers::Upload;
|
using Syncers::Upload;
|
||||||
|
|
||||||
string songPath;
|
string songPath;
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ namespace Managers
|
|||||||
fileBuffer = new char [fileBufferLength];
|
fileBuffer = new char [fileBufferLength];
|
||||||
|
|
||||||
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
|
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
|
||||||
// read data as a block:
|
|
||||||
is.read (fileBuffer,fileBufferLength);
|
is.read (fileBuffer,fileBufferLength);
|
||||||
|
|
||||||
if (is)
|
if (is)
|
||||||
@@ -62,4 +61,6 @@ namespace Managers
|
|||||||
{
|
{
|
||||||
return fileBuffer;
|
return fileBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FileManager::retrieveFileBufferLength() const { return fileBufferLength; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace Managers
|
|||||||
void modifyFilePath(std::string);
|
void modifyFilePath(std::string);
|
||||||
|
|
||||||
char* retrieveFileBuffer() const;
|
char* retrieveFileBuffer() const;
|
||||||
|
int retrieveFileBufferLength() const;
|
||||||
private:
|
private:
|
||||||
void readFile();
|
void readFile();
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
|
|
||||||
#include<string>
|
#include<string>
|
||||||
|
|
||||||
#include<nlohmann/json.hpp>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
|
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
#include"Download.h"
|
#include"Download.h"
|
||||||
|
|
||||||
Download::Download() { }
|
namespace Syncers
|
||||||
|
{
|
||||||
|
Download::Download() { }
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Syncers
|
|||||||
public:
|
public:
|
||||||
Download();
|
Download();
|
||||||
private:
|
private:
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+17
-10
@@ -26,20 +26,28 @@ namespace Syncers
|
|||||||
|
|
||||||
void Upload::uploadSong()
|
void Upload::uploadSong()
|
||||||
{
|
{
|
||||||
configureSong();
|
configureSongDemo();
|
||||||
json jObj = serializeObject();
|
|
||||||
printJsonData(jObj);
|
|
||||||
|
|
||||||
std::string url = apiUrl + apiEndPoint;
|
string url = apiUrl + ":" + std::to_string(port) + apiEndPoint;
|
||||||
|
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
try
|
||||||
cpr::Multipart{{"key", "file"},
|
{
|
||||||
{"value", cpr::File{songPath}}});
|
auto r = cpr::Post(cpr::Url{url},
|
||||||
cout << r.text << std::endl;
|
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;
|
int id = 0;
|
||||||
string title = "What of it?";
|
string title = "What of it?";
|
||||||
@@ -59,7 +67,6 @@ namespace Syncers
|
|||||||
this->song.duration = duration;
|
this->song.duration = duration;
|
||||||
this->song.songData = fMgr.retrieveFileBuffer();
|
this->song.songData = fMgr.retrieveFileBuffer();
|
||||||
cout<<*song.songData<<endl;
|
cout<<*song.songData<<endl;
|
||||||
printSongDetails();
|
|
||||||
}
|
}
|
||||||
void Upload::printSongDetails()
|
void Upload::printSongDetails()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ namespace Syncers
|
|||||||
private:
|
private:
|
||||||
Managers::FileManager fMgr;
|
Managers::FileManager fMgr;
|
||||||
Models::Song song;
|
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 apiEndPoint{"/api/song/data"};
|
||||||
std::string songPath;
|
std::string songPath;
|
||||||
int port{9349};
|
int port{9349};
|
||||||
|
|
||||||
void configureSong();
|
void configureSongDemo();
|
||||||
void printSongDetails();
|
void printSongDetails();
|
||||||
void printJsonData(nlohmann::json);
|
void printJsonData(nlohmann::json);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user