Refine files upload.
This commit is contained in:
+2
-43
@@ -1,33 +1,13 @@
|
||||
#include "webcc/globals.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
#include "boost/filesystem/path.hpp"
|
||||
|
||||
#include "webcc/version.h"
|
||||
|
||||
namespace webcc {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Read entire file into string.
|
||||
static bool ReadFile(const std::string& path, std::string* output) {
|
||||
std::ifstream ifs{path, std::ios::binary | std::ios::ate};
|
||||
if (!ifs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto size = ifs.tellg();
|
||||
output->resize((std::size_t)size, '\0');
|
||||
ifs.seekg(0);
|
||||
ifs.read(&(*output)[0], size); // TODO: Error handling
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
namespace http {
|
||||
|
||||
const std::string& UserAgent() {
|
||||
@@ -35,29 +15,6 @@ const std::string& UserAgent() {
|
||||
return s_user_agent;
|
||||
}
|
||||
|
||||
File::File(const std::string& file_path) {
|
||||
if (!ReadFile(file_path, &data)) {
|
||||
throw Exception(kFileIOError, "Cannot read the file.");
|
||||
}
|
||||
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
// Determine file name from file path.
|
||||
//if (file_name.empty()) {
|
||||
file_name = bfs::path(file_path).filename().string();
|
||||
//} else {
|
||||
// file_name = file_name;
|
||||
//}
|
||||
|
||||
// Determine content type from file extension.
|
||||
//if (mime_type.empty()) {
|
||||
std::string extension = bfs::path(file_path).extension().string();
|
||||
mime_type = http::media_types::FromExtension(extension, false);
|
||||
//} else {
|
||||
//mime_type = mime_type;
|
||||
//}
|
||||
}
|
||||
|
||||
namespace media_types {
|
||||
|
||||
// TODO: Add more.
|
||||
@@ -97,6 +54,8 @@ std::string FromExtension(const std::string& extension,
|
||||
|
||||
} // namespace http
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const char* DescribeError(Error error) {
|
||||
switch (error) {
|
||||
case kSchemaError:
|
||||
|
||||
Reference in New Issue
Block a user