Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]The uploaded file cannot be saved locally #270

Open
1 task
XinHengW opened this issue May 19, 2022 · 3 comments
Open
1 task

[BUG]The uploaded file cannot be saved locally #270

XinHengW opened this issue May 19, 2022 · 3 comments
Assignees
Labels
bug Confirmed bugs or reports that are very likely to be bugs.

Comments

@XinHengW
Copy link

Prerequisites

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 XinHengW added the bug Confirmed bugs or reports that are very likely to be bugs. label May 19, 2022
@etr
Copy link
Owner

etr commented May 19, 2022

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

@XinHengW
Copy link
Author

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!!!!!

@LeSpocky
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs.
Projects
None yet
Development

No branches or pull requests

3 participants