Improve:goahead upload file function.
This commit is contained in:
parent
dd0a7304f5
commit
2db19bc9b6
|
@ -31,6 +31,7 @@ set(TARGET_PLATFORM "linux")
|
||||||
set(SUBMODULE_PATH_OF_IPC_SDK "")
|
set(SUBMODULE_PATH_OF_IPC_SDK "")
|
||||||
set(PLATFORM_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
|
set(PLATFORM_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
set(TEST_COVERAGE "true")
|
set(TEST_COVERAGE "true")
|
||||||
|
add_definitions(-DPLATFORM_PATH=\"${PLATFORM_PATH}\")
|
||||||
|
|
||||||
# ------------ build curl + openssl ------------ #
|
# ------------ build curl + openssl ------------ #
|
||||||
set(CURL_OPENSSL_LIB_SHARED_ENABLE "false")
|
set(CURL_OPENSSL_LIB_SHARED_ENABLE "false")
|
||||||
|
@ -44,6 +45,7 @@ set(LOG_SUPPORT "true")
|
||||||
# ------------ build GoAhead ------------ #
|
# ------------ build GoAhead ------------ #
|
||||||
set(GOAHEAD_DOCUMENTS_PATH "web")
|
set(GOAHEAD_DOCUMENTS_PATH "web")
|
||||||
set(GOAHEAD_UPLOAD_TMP_PATH "./goahead")
|
set(GOAHEAD_UPLOAD_TMP_PATH "./goahead")
|
||||||
|
set(GOAHEAD_UPLOAD_PATH "${GOAHEAD_UPLOAD_TMP_PATH}")
|
||||||
# GOAHEAD_CONFIG_FILE_PATH should be set when cross compile
|
# GOAHEAD_CONFIG_FILE_PATH should be set when cross compile
|
||||||
# set(GOAHEAD_CONFIG_FILE_PATH "./")
|
# set(GOAHEAD_CONFIG_FILE_PATH "./")
|
||||||
# ------------ build GoAhead end ------------ #
|
# ------------ build GoAhead end ------------ #
|
||||||
|
|
|
@ -69,7 +69,7 @@ void ServersMock::MockUploadFiles(void)
|
||||||
std::string mockRequest = mServerUrl + "/upload";
|
std::string mockRequest = mServerUrl + "/upload";
|
||||||
ServerHttp *http = NewServersHttp(mockRequest.c_str());
|
ServerHttp *http = NewServersHttp(mockRequest.c_str());
|
||||||
if (http) {
|
if (http) {
|
||||||
http->filePath = (char *)"./web/test.mp4";
|
http->filePath = (char *)PLATFORM_PATH "/output_files/test/bin/AppManagerTest";
|
||||||
HttpPostFile(http);
|
HttpPostFile(http);
|
||||||
if (http->reply) {
|
if (http->reply) {
|
||||||
char *replyStr = (char *)malloc(http->replyLength + 1);
|
char *replyStr = (char *)malloc(http->replyLength + 1);
|
||||||
|
|
|
@ -27,12 +27,19 @@ endif()
|
||||||
add_definitions(-DGOAHEAD_DOCUMENTS_PATH=\"${GOAHEAD_DOCUMENTS_PATH}\")
|
add_definitions(-DGOAHEAD_DOCUMENTS_PATH=\"${GOAHEAD_DOCUMENTS_PATH}\")
|
||||||
|
|
||||||
if (NOT DEFINED GOAHEAD_UPLOAD_TMP_PATH)
|
if (NOT DEFINED GOAHEAD_UPLOAD_TMP_PATH)
|
||||||
message(FATAL_ERROR "YYou should set the GOAHEAD_UPLOAd_TMP_PATH variable so that the GOAHEAD module can temporarily save uploaded files.
|
message(FATAL_ERROR "YYou should set the GOAHEAD_UPLOAD_TMP_PATH variable so that the GOAHEAD module can temporarily save uploaded files.
|
||||||
For example: set(GOAHEAD_UPLOAd_TMP_PATH \"./goahead\")
|
For example: set(GOAHEAD_UPLOAD_TMP_PATH \"./goahead\")
|
||||||
See:${IPC_SDK_PATH}/build/cmake/toolchain/linux.toolchain.cmake")
|
See:${IPC_SDK_PATH}/build/cmake/toolchain/linux.toolchain.cmake")
|
||||||
endif()
|
endif()
|
||||||
add_definitions(-DGOAHEAD_UPLOAD_TMP_PATH=\"${GOAHEAD_UPLOAD_TMP_PATH}\")
|
add_definitions(-DGOAHEAD_UPLOAD_TMP_PATH=\"${GOAHEAD_UPLOAD_TMP_PATH}\")
|
||||||
|
|
||||||
|
if (NOT DEFINED GOAHEAD_UPLOAD_PATH)
|
||||||
|
message(FATAL_ERROR "YYou should set the GOAHEAD_UPLOAD_PATH variable so that the GOAHEAD module can temporarily save uploaded files.
|
||||||
|
For example: set(GOAHEAD_UPLOAD_PATH \"./goahead\")
|
||||||
|
See:${IPC_SDK_PATH}/build/cmake/toolchain/linux.toolchain.cmake")
|
||||||
|
endif()
|
||||||
|
add_definitions(-DGOAHEAD_UPLOAD_PATH=\"${GOAHEAD_UPLOAD_PATH}\")
|
||||||
|
|
||||||
aux_source_directory(./src SRC_FILES)
|
aux_source_directory(./src SRC_FILES)
|
||||||
|
|
||||||
set(TARGET_NAME WebServer)
|
set(TARGET_NAME WebServer)
|
||||||
|
@ -93,7 +100,7 @@ add_custom_command(
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
libgo.a
|
libgo.a
|
||||||
DEPENDS ${EXTERNAL_LIBS_OUTPUT_PATH}/libgo.a
|
DEPENDS ${EXTERNAL_LIBS_OUTPUT_PATH}/libgo.a
|
||||||
COMMAND mkdir ${GOAHEAD_UPLOAD_TMP_PATH}
|
# COMMAND mkdir ${GOAHEAD_UPLOAD_TMP_PATH}
|
||||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,27 @@ static void sigHandler(int signo)
|
||||||
LogInfo("Stop goahead web server.\n");
|
LogInfo("Stop goahead web server.\n");
|
||||||
finished = 1;
|
finished = 1;
|
||||||
}
|
}
|
||||||
|
static void CheckUploadDir(void)
|
||||||
|
{
|
||||||
|
const char *directory = GOAHEAD_UPLOAD_TMP_PATH;
|
||||||
|
int result = mkdir(directory, 0777);
|
||||||
|
|
||||||
|
if (result == 0) {
|
||||||
|
LogInfo("mkdir upload tmp path successfuly.\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogError("mkdir upload tmp path failed.\n");
|
||||||
|
}
|
||||||
|
const char *directory2 = GOAHEAD_UPLOAD_PATH;
|
||||||
|
result = mkdir(directory2, 0777);
|
||||||
|
|
||||||
|
if (result == 0) {
|
||||||
|
LogInfo("mkdir upload path successfuly.\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogError("mkdir upload path failed.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
static void logHeader(void)
|
static void logHeader(void)
|
||||||
{
|
{
|
||||||
char home[ME_GOAHEAD_LIMIT_STRING];
|
char home[ME_GOAHEAD_LIMIT_STRING];
|
||||||
|
@ -72,7 +93,7 @@ static bool AppUploadHandle(Webs *wp)
|
||||||
{
|
{
|
||||||
WebsKey *s;
|
WebsKey *s;
|
||||||
WebsUpload *up;
|
WebsUpload *up;
|
||||||
char *upfile;
|
char *upfile = nullptr;
|
||||||
|
|
||||||
websSetStatus(wp, 200);
|
websSetStatus(wp, 200);
|
||||||
websWriteHeaders(wp, -1, 0);
|
websWriteHeaders(wp, -1, 0);
|
||||||
|
@ -82,16 +103,18 @@ static bool AppUploadHandle(Webs *wp)
|
||||||
if (scaselessmatch(wp->method, "POST")) {
|
if (scaselessmatch(wp->method, "POST")) {
|
||||||
for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) {
|
for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) {
|
||||||
up = (WebsUpload *)s->content.value.symbol;
|
up = (WebsUpload *)s->content.value.symbol;
|
||||||
LogInfo("FILE: %s\r\n", s->name.value.string);
|
// LogInfo("FILE: %s\r\n", s->name.value.string);
|
||||||
LogInfo("FILENAME=%s\r\n", up->filename);
|
// LogInfo("FILENAME=%s\r\n", up->filename);
|
||||||
LogInfo("CLIENT=%s\r\n", up->clientFilename);
|
LogInfo("CLIENT=%s\r\n", up->clientFilename);
|
||||||
LogInfo("TYPE=%s\r\n", up->contentType);
|
// LogInfo("TYPE=%s\r\n", up->contentType);
|
||||||
LogInfo("SIZE=%d\r\n", up->size);
|
LogInfo("SIZE=%d\r\n", up->size);
|
||||||
upfile = sfmt("%s/tmp/%s", websGetDocuments(), up->clientFilename);
|
upfile = sfmt(GOAHEAD_UPLOAD_PATH "/%s", up->clientFilename);
|
||||||
if (rename(up->filename, upfile) < 0) {
|
if (rename(up->filename, upfile) < 0) {
|
||||||
error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, upfile, errno);
|
error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, upfile, errno);
|
||||||
}
|
}
|
||||||
|
LogInfo("Upload file:%s\n", upfile);
|
||||||
wfree(upfile);
|
wfree(upfile);
|
||||||
|
upfile = nullptr;
|
||||||
}
|
}
|
||||||
gHttpHandle(wp->url, 0, response_handle, wp);
|
gHttpHandle(wp->url, 0, response_handle, wp);
|
||||||
}
|
}
|
||||||
|
@ -100,6 +123,7 @@ static bool AppUploadHandle(Webs *wp)
|
||||||
}
|
}
|
||||||
StatusCode WebServerInit(const WebServerParam webParam)
|
StatusCode WebServerInit(const WebServerParam webParam)
|
||||||
{
|
{
|
||||||
|
CheckUploadDir();
|
||||||
websSetDebug(1);
|
websSetDebug(1);
|
||||||
logSetPath("stdout:2");
|
logSetPath("stdout:2");
|
||||||
const char *documents = GOAHEAD_DOCUMENTS_PATH;
|
const char *documents = GOAHEAD_DOCUMENTS_PATH;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user