Allow S3 Uploads while "Include Subdirectories" is False#2760
Allow S3 Uploads while "Include Subdirectories" is False#2760MichaIng merged 2 commits intomotioneye-project:devfrom
Conversation
|
Many thanks, makes perfectly sense. This actually makes Also here in the code, while the argument positions must not change, we can at least not assign |
|
I agree with Micha on also hiding the "Include subfolders" switch for S3 upload, so that we do not degrade the user experience with controls that do not cause any action or change. Otherwise, good catch and thanks for the PR. I have no opinion regarding target_dir parameter in upload_file (camera_name was actually already not in use there, which my editor indicated readily), I'm ok with whatever practice for that that is used in Python. |
|
Some users, including myself, have the Movie File Name that includes also slashes to create subfolders automatically (for example |
|
Cycling back here after a question regarding the filename appeared in #3192, and then checking #2912:
|
`path.basename(filename)` strips as well the relative path from the filename, which breaks the ability to upload to S3 buckets with subdirectories included via slashes in the filename input. This commit takes the logic from the base upload_file method to preserve the correct relative path if subdirectories shall be included, stripping away possible leading slashes, which was another issue that could appear. Additionally, the leading slashes are now `lstrip`ped from the path, instead of using a while loop, simplifying code, and the debug message now shows the path the file is uploaded to. Signed-off-by: MichaIng <micha@dietpi.com>
|
@pbouill @serniko97 could you test whether this solves it for you, both with and without included subdirs, and when adding those dirs via filename input? The method to strip leading slashes from the relative path, if subdirs shall be preserved, should be failsafe now. |
MichaIng
left a comment
There was a problem hiding this comment.
Works well with MinIO. I could not replicate the leading slash issue with the old code either, but I guess it depends on the exact S3 server (version) whether it strips leading slashes automatically or not. At least it does not depend on boto3, since I can see the doubled slash (between bucket name and file path) in the debug output PUT URL, but MinIO seems to strip it automatically.
Anyway, the new code strips it correctly our end, which can be also seen in the logs, and it allows to disable subdirs, which as well works correctly, and which was the original purpose of this PR.
Can't upload to S3 if "target_dir" is false... simplify code to get the filename using os.path -- just get the file name directly without slicing the file name string (filename[len(target_dir) :]))
Was getting: