Preserve original filename when opening cura:// URLs#21537
Open
Nikolay Zinov (nzinov) wants to merge 1 commit into
Open
Preserve original filename when opening cura:// URLs#21537Nikolay Zinov (nzinov) wants to merge 1 commit into
Nikolay Zinov (nzinov) wants to merge 1 commit into
Conversation
The on_finish handler in CuraApplication._openUrl carefully extracts the original filename (from Content-Disposition or the URL path), but then passes it as the 'suffix' argument to tempfile.NamedTemporaryFile, which produces a file named 'tmpXXXXXX<filename>' — so the name shown in Cura (and suggested on save) is something like 'tmpAbC123model.stl'. Write the download to a fresh temp directory under its real filename instead. Users opening models from Thingiverse's 'Send to Cura' (and anything else using the cura:// URL scheme) now see the actual model name.
Contributor
Contributor
|
Hi Nikolay Zinov (@nzinov) thank you for the PR, seems like useful addition. Could you share how this feature has been tested? I do recall our team trying something like this, but running into the issue where tempfolders would be cleared before we could load them where tempfiles would not. |
Author
|
Casper Lamboo (@casperlamboo) I use it locally on my machine without any problems for a while now, but I have not tested it otherwise. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a model is opened via a
cura://open?file=…URL (e.g. Thingiverse's "Send to Cura" button), the downloaded file is shown in Cura with a name liketmpAbC123model.stlinstead ofmodel.stl.The handler in
CuraApplication._openUrlalready does the work to recover the real filename — it parses theContent-Dispositionheader, and falls back to the last URL path segment. But it then passes that name as thesuffixargument totempfile.NamedTemporaryFile, which producestmpXXXXXX<suffix>. So the careful filename extraction is effectively wasted.This PR writes the download to a fresh temp directory under its real filename instead. The temp file is still disposable, but the name Cura displays (and suggests on save) is now the original model name.
Before / after
tmpAbC123thingiverse_123456_model.stlthingiverse_123456_model.stl