Skip to content

Sanitize attachment filenames before saving so they are acceptable by QFieldCloud #6197

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 1 commit into from
May 1, 2025

Conversation

suricactus
Copy link
Collaborator

QFieldCloud recently added a restriction for file names so they can work on all popular operating systems. However, the attachment naming expressions have no restrictions to what they are going to evaluate.

Therefore the new FileUtils::sanitizeFilePath function has been added that will convert the disallowed chars into underscores and return an empty string when the file path cannot be fixed, for example when it is too long.

If an empty string is returned,then the default naming kicks in to guarantee the filename can be saved and can be uploaded to QFieldCloud.


QFieldSync config:
image
Resulting values:
image

@suricactus suricactus requested a review from nirvn April 24, 2025 00:57
Copy link

sentry-io bot commented Apr 24, 2025

Sentry Issue: QFIELDCLOUD-2YD

@suricactus suricactus force-pushed the QF-5868-fix_attachment_upload branch 2 times, most recently from 0c5364c to c6dfe7f Compare April 24, 2025 01:01
@qfield-fairy
Copy link
Collaborator

qfield-fairy commented Apr 24, 2025

@suricactus suricactus force-pushed the QF-5868-fix_attachment_upload branch from c6dfe7f to 0d86867 Compare April 25, 2025 07:57
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@duke-nyuki
Copy link

… QFieldCloud

QFieldCloud recently added a restriction for file names so they can work on all
popular operating systems. However, the attachment naming expressions have no
restrictions to what they are going to evaluate.

Therefore the new `FileUtils::sanitizeFilePath` function has been added
that will convert the disallowed chars into underscores and return an empty
string when the file path cannot be fixed, for example when it is too long.

If an empty string is returned,then the default naming kicks in to guarantee
the filename can be saved and can be uploaded to QFieldCloud.
@suricactus suricactus force-pushed the QF-5868-fix_attachment_upload branch from d30a86d to d423855 Compare April 30, 2025 20:17
@suricactus
Copy link
Collaborator Author

@nirvn finally ready for a review.

@nirvn
Copy link
Member

nirvn commented May 1, 2025

Let's merge that and get our ~3,000 unstable user to stress test it.

@suricactus suricactus merged commit 9a1a978 into master May 1, 2025
25 checks passed
@suricactus suricactus deleted the QF-5868-fix_attachment_upload branch May 1, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants