libhttpserver icon indicating copy to clipboard operation
libhttpserver copied to clipboard

[BUG]The uploaded file cannot be saved locally

Open XinHengW opened this issue 2 years ago • 3 comments

Prerequisites

  • [ ] Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo%3Aetr%2Flibhttpserver&type=Issues

Description

[Description of the issue]

Steps to Reproduce

  1. [First Step]
  2. [Second Step]
  3. [and so on...]

Expected behavior: [What you expect to happen]

Actual behavior: [What actually happens]

Reproduces how often: [What percentage of the time does it reproduce?]

Versions

  • OS version (if on linux, the output of "uname -a")
  • libhttpserver version (please specify whether compiled or packaged)
  • libmicrohttpd version (please specify whether compiled or packaged)

If you have problems during build:

  • Compiler version
  • autotools version

Additional Information

Any additional information, configuration (especially build configuration flags if you compiled the libraries) or data that might be necessary to reproduce the issue.

If you have problems during build, please attach your config.log and the full scope of your error from make.

If you have problems at execution, please:

  • attach the stacktrace in case of crash (a coredump would be even better).
  • provide a main that reproduces the error.

XinHengW avatar May 19 '22 09:05 XinHengW

Can you provide more details on the issue and how to reproduce. Filling the template above helps as well.

etr avatar May 19 '22 17:05 etr

Run httpserver and upload files by post. After uploading, the uploaded files will be automatically deleted by httpserver. After changing the code like this: MHD_Result webserver::complete_request(MHD_Connection* connection, struct details::modded_request* mr, const char* version, const char* method) { mr->ws = this; mr->dhr->set_path(mr->standardized_url->c_str()); mr->dhr->set_method(method); mr->dhr->set_version(version); /*I changed!*/ _http::file_info& file = mr->dhr->get_or_create_file_info(mr->upload_key,mr->upload_filename); std::string real_name =mr->ws->file_upload_dir + "/" + mr->upload_filename; rename(file.get_file_system_file_name().data(),real_name.data());_ /*end*/ return finalize_answer(connection, mr, method); } The file can be saved under its real name. When the "rename()" function is commented out, no files can be saved. step of reproduce: 1 run httpserver /home/data 2 upload "test.txt" by postman 3 can't find any file uploaded

thanks!!!!!

XinHengW avatar May 24 '22 10:05 XinHengW

Run httpserver and upload files by post. After uploading, the uploaded files will be automatically deleted by httpserver.

There was a lengthy discussion about this in #264 and the actual behavior you probably experienced, was implemented with #266.

Short term solution: if you need the file to be persistent, copy it in your request handler to some place of your choice.

Long term solution: propose something to properly solve #264.

LeSpocky avatar May 24 '22 10:05 LeSpocky