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(PLATFORM_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(TEST_COVERAGE "true")
|
||||
add_definitions(-DPLATFORM_PATH=\"${PLATFORM_PATH}\")
|
||||
|
||||
# ------------ build curl + openssl ------------ #
|
||||
set(CURL_OPENSSL_LIB_SHARED_ENABLE "false")
|
||||
|
@ -44,6 +45,7 @@ set(LOG_SUPPORT "true")
|
|||
# ------------ build GoAhead ------------ #
|
||||
set(GOAHEAD_DOCUMENTS_PATH "web")
|
||||
set(GOAHEAD_UPLOAD_TMP_PATH "./goahead")
|
||||
set(GOAHEAD_UPLOAD_PATH "${GOAHEAD_UPLOAD_TMP_PATH}")
|
||||
# GOAHEAD_CONFIG_FILE_PATH should be set when cross compile
|
||||
# set(GOAHEAD_CONFIG_FILE_PATH "./")
|
||||
# ------------ build GoAhead end ------------ #
|
||||
|
|
|
@ -69,7 +69,7 @@ void ServersMock::MockUploadFiles(void)
|
|||
std::string mockRequest = mServerUrl + "/upload";
|
||||
ServerHttp *http = NewServersHttp(mockRequest.c_str());
|
||||
if (http) {
|
||||
http->filePath = (char *)"./web/test.mp4";
|
||||
http->filePath = (char *)PLATFORM_PATH "/output_files/test/bin/AppManagerTest";
|
||||
HttpPostFile(http);
|
||||
if (http->reply) {
|
||||
char *replyStr = (char *)malloc(http->replyLength + 1);
|
||||
|
|
|
@ -27,12 +27,19 @@ endif()
|
|||
add_definitions(-DGOAHEAD_DOCUMENTS_PATH=\"${GOAHEAD_DOCUMENTS_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.
|
||||
For example: set(GOAHEAD_UPLOAd_TMP_PATH \"./goahead\")
|
||||
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\")
|
||||
See:${IPC_SDK_PATH}/build/cmake/toolchain/linux.toolchain.cmake")
|
||||
endif()
|
||||
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)
|
||||
|
||||
set(TARGET_NAME WebServer)
|
||||
|
@ -93,7 +100,7 @@ add_custom_command(
|
|||
add_custom_target(
|
||||
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/
|
||||
)
|
||||
|
||||
|
|
|
@ -24,6 +24,27 @@ static void sigHandler(int signo)
|
|||
LogInfo("Stop goahead web server.\n");
|
||||
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)
|
||||
{
|
||||
char home[ME_GOAHEAD_LIMIT_STRING];
|
||||
|
@ -72,7 +93,7 @@ static bool AppUploadHandle(Webs *wp)
|
|||
{
|
||||
WebsKey *s;
|
||||
WebsUpload *up;
|
||||
char *upfile;
|
||||
char *upfile = nullptr;
|
||||
|
||||
websSetStatus(wp, 200);
|
||||
websWriteHeaders(wp, -1, 0);
|
||||
|
@ -82,16 +103,18 @@ static bool AppUploadHandle(Webs *wp)
|
|||
if (scaselessmatch(wp->method, "POST")) {
|
||||
for (s = hashFirst(wp->files); s; s = hashNext(wp->files, s)) {
|
||||
up = (WebsUpload *)s->content.value.symbol;
|
||||
LogInfo("FILE: %s\r\n", s->name.value.string);
|
||||
LogInfo("FILENAME=%s\r\n", up->filename);
|
||||
// LogInfo("FILE: %s\r\n", s->name.value.string);
|
||||
// LogInfo("FILENAME=%s\r\n", up->filename);
|
||||
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);
|
||||
upfile = sfmt("%s/tmp/%s", websGetDocuments(), up->clientFilename);
|
||||
upfile = sfmt(GOAHEAD_UPLOAD_PATH "/%s", up->clientFilename);
|
||||
if (rename(up->filename, upfile) < 0) {
|
||||
error("Cannot rename uploaded file: %s to %s, errno %d", up->filename, upfile, errno);
|
||||
}
|
||||
LogInfo("Upload file:%s\n", upfile);
|
||||
wfree(upfile);
|
||||
upfile = nullptr;
|
||||
}
|
||||
gHttpHandle(wp->url, 0, response_handle, wp);
|
||||
}
|
||||
|
@ -100,6 +123,7 @@ static bool AppUploadHandle(Webs *wp)
|
|||
}
|
||||
StatusCode WebServerInit(const WebServerParam webParam)
|
||||
{
|
||||
CheckUploadDir();
|
||||
websSetDebug(1);
|
||||
logSetPath("stdout:2");
|
||||
const char *documents = GOAHEAD_DOCUMENTS_PATH;
|
||||
|
|
Loading…
Reference in New Issue
Block a user