-
Notifications
You must be signed in to change notification settings - Fork 191
Add options to store files directly to the file system and to omit duplicating files in memory #257
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
5f22dfd
Add options to store files directly to the file system and to omit du…
ctomahogh 916610a
Delete accidentially added newline in http_resource.hpp
ctomahogh d9adfcb
Removed unused function, fixed some code style and typos in comments
ctomahogh 220fdd8
Removed asprintf in favor or string concatenation
ctomahogh 52cb06f
Made http_utils::generate_random_upload_filename plattform independant
ctomahogh 71d1f20
Input and output of http_utils::generate_random_upload_filename are c…
ctomahogh 1f37cfa
Added options and functions for file upload to README.md
ctomahogh fac086a
Use correct include and functions in generate_random_upload_filename …
ctomahogh 5843f5f
Add missing includes for windows, fixed wrong argument for _mktemp_s
ctomahogh bc5a4fe
Removed accidentially pushed debug code
ctomahogh 8d7ea8e
Use a static const char* for the random file system template
ctomahogh 329c066
Make output of get_or_create_file_info const and introduce new setters
ctomahogh 07e9f4d
Use const variables for the webserver options
ctomahogh 29ba743
Added an example for file upload
ctomahogh 2606d61
Use a prefixed operator in for loop
ctomahogh 8ab2972
Added safety check for use of strlen and some missing free()s
ctomahogh 3880d8d
Changed file map to be a map of keys with a nested map of files
ctomahogh 2e99b1d
Adjusted file_upload example to use new files map
ctomahogh fd7bab9
Updated description of files map in README.md
ctomahogh ccc67e8
Removed strlen from generate_random_upload_filename
ctomahogh 799c201
Use a pointer to std::ofstream in modded_request
ctomahogh f329061
Moved struct file_info_s to class file_info
ctomahogh 8b5c172
Setters of class file_info are private and class webserver is a frien…
ctomahogh cb802d1
Use const reference as parameter for set_file_system_file_name
ctomahogh c6151c4
Don't create zero length files if no file is uploaded
ctomahogh 4cb49c8
Updated README.md as file_info is now a class
ctomahogh 7f2c353
Some code styling and small refactorings after review
ctomahogh 27fc9a8
Replaced std::exception with custom generateFilenameException
ctomahogh 1cf683e
Some more comments and code style fixes after review
ctomahogh 88d14aa
Some more code style changes after review
ctomahogh b3a39dd
Added error string to generateFilenameException
ctomahogh cbca260
Added comment for c functions in generate_random_upload_filename
ctomahogh f896540
Removed const qualifier from file_info::get_file_size()
ctomahogh 897eab9
Merge branch 'etr:master' into upload_to_file_system
ctomahogh 7b73c48
Added unit test for generate_random_upload_filename
ctomahogh 4f2cecf
Removed filesystem include from unit tests again, as it would require…
ctomahogh c1878f5
Close open upload file after post processor is done
ctomahogh f189014
Added content_type and transfer_encoding to file_info
ctomahogh 8e16406
Fixed file_upload example
ctomahogh 4bcc846
Made filename_template and path_separator part of class http_utils
ctomahogh f4fb34f
Added integration test for file upload
ctomahogh 0e90742
Fixed integration test for file upload
ctomahogh ee91ea9
Merge branch 'etr:master' into upload_to_file_system
ctomahogh ac91c63
Removed empty AUTO_TEST from file_upload integration test
ctomahogh f13d1fe
Use internal values for http_ressource class in integration tests
ctomahogh 91b90e5
Added further integration tests for file upload
ctomahogh 4de82c9
Added test_content_2 to configure script
ctomahogh acebdfa
Fixed memory leak in post_iterator
ctomahogh 6fff5f0
Some code style fixed on file upload integration test
ctomahogh dbba47c
Use map definition instead of auto in integration test
ctomahogh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make output of get_or_create_file_info const and introduce new setters
The output of get_or_create_file_info should be const. As previously the result was used to direclty alter the content of the struct new setters to set the file_system_file_name and to grow the size are introduced (and used)
- Loading branch information
commit 329c066662c4fbf91d2838292a03540535c3d9f3
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,7 +141,7 @@ class http_request { | |
| * @param upload_file_name the file name the user uploaded (this is the identifier for the map entry) | ||
| * @result a file info struct file_info_s | ||
| **/ | ||
| file_info_s &get_or_create_file_info(const char *upload_file_name); | ||
| const file_info_s& get_or_create_file_info(const std::string& upload_file_name); | ||
|
|
||
| /** | ||
| * Method used to get all files passed with the request. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼 |
||
|
|
@@ -318,6 +318,24 @@ class http_request { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Method used to set the file system file name into the map by key. | ||
| * @param upload_file_name The file name the user uploaded (identifying the map entry) | ||
| * @param file_system_file_name The path to the file in the file system (the name may not be the original name depending on configuration of the webserver) | ||
| **/ | ||
| void set_file_system_file_name(const std::string& upload_file_name, const std::string& file_system_file_name) { | ||
| files[upload_file_name].file_system_file_name = file_system_file_name; | ||
| } | ||
|
|
||
| /** | ||
| * Method used grow the filesize of an entry in the map by key. | ||
| * @param upload_file_name The file name the user uploaded (identifying the map entry) | ||
| * @param additional_file_size The additional size as a number to be added to the entry. | ||
| **/ | ||
| void grow_file_size(const std::string& upload_file_name, size_t additional_file_size) { | ||
| files[upload_file_name].file_size += additional_file_size; | ||
| } | ||
|
|
||
|
ctomahogh marked this conversation as resolved.
Outdated
|
||
| /** | ||
| * Method used to set the path requested. | ||
| * @param path The path searched by the request. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -471,14 +471,14 @@ MHD_Result webserver::post_iterator(void *cls, enum MHD_ValueKind kind, | |
|
|
||
| if (filename && mr->ws->file_upload_target != FILE_UPLOAD_MEMORY_ONLY) { | ||
| // either get the existing file info struct or create a new one in the file map | ||
| file_info_s &file_info = mr->dhr->get_or_create_file_info(filename); | ||
| const file_info_s &file_info = mr->dhr->get_or_create_file_info(filename); | ||
| // if the file_system_file_name is not filled yet, this is a new entry and the name has to be set | ||
| // (either random or copy of the original filename) | ||
| if (file_info.file_system_file_name.empty()) { | ||
| if (mr->ws->generate_random_filename_on_upload) { | ||
| file_info.file_system_file_name = http_utils::generate_random_upload_filename(mr->ws->post_upload_dir); | ||
| mr->dhr->set_file_system_file_name(filename, http_utils::generate_random_upload_filename(mr->ws->post_upload_dir)); | ||
| } else { | ||
| file_info.file_system_file_name = mr->ws->post_upload_dir + "/" + std::string(filename); | ||
| mr->dhr->set_file_system_file_name(filename, mr->ws->post_upload_dir + "/" + std::string(filename)); | ||
| } | ||
| // to not append to an already existing file, delete an already existing file | ||
| unlink(file_info.file_system_file_name.c_str()); | ||
|
|
@@ -499,7 +499,7 @@ MHD_Result webserver::post_iterator(void *cls, enum MHD_ValueKind kind, | |
| } | ||
|
|
||
| // update the file size in the map | ||
| file_info.file_size += size; | ||
| mr->dhr->grow_file_size(filename, size); | ||
| } | ||
| return MHD_YES; | ||
| } catch(const std::exception& e) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will fix itself when we use the custom exception |
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.