Skip to content

[fix]: Error on subdirectory file uploads on Windows - #132

Open
SeqLaz wants to merge 1 commit into
masterfrom
fixing_windows_validation_error
Open

SeqLaz wants to merge 1 commit into
masterfrom
fixing_windows_validation_error

Conversation

@SeqLaz

@SeqLaz SeqLaz commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Fixes 400 Bad Request (validation_error) failures when uploading project files located in subdirectories from Windows

example:

File "DCIM\point-40843027.jpg" failed to upload: Requested "https://staging.qfield.cloud/api/v1/files/cab4e790-22fb-4ebf-bd7f-f225470114b3/DCIM%5Cpexels-foatographer-40843027.jpg/" and got "400 Bad Request":
{
  "code": "validation_error",
  "message": "Validation error"
} .

The root of the error is due to the backslash passed to the URL (%5C)

@SeqLaz
SeqLaz requested a review from suricactus December 3, 2026 15:50
@SeqLaz
SeqLaz force-pushed the fixing_windows_validation_error branch from bce4586 to ee431c3 Compare December 3, 2026 15:56

@suricactus suricactus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix! A few small changes to do before merging.

Comment thread qfieldcloud_sdk/sdk.py
# if the filepath is invalid, it will throw a new error `pathvalidate.ValidationError`
is_valid_filepath(str(local_filename))

remote_filename_posix = Path(remote_filename).as_posix()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
remote_filename_posix = Path(remote_filename).as_posix()

Keep the empty line above, and actually move this where it is used. IMO we don't even need the variable.

Comment thread qfieldcloud_sdk/sdk.py
unit_scale=True,
unit="B",
desc=f'Uploading "{remote_filename}"...',
desc=f'Uploading "{remote_filename_posix}"...',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
desc=f'Uploading "{remote_filename_posix}"...',
desc=f'Uploading "{remote_filename}"...',

This is shown to the user, use the local file path slash convention.

Comment thread qfieldcloud_sdk/sdk.py
encoder_params["callback"] = cb
else:
logger.info(f'Uploading file "{remote_filename}"…')
logger.info(f'Uploading file "{remote_filename_posix}"…')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
logger.info(f'Uploading file "{remote_filename_posix}"…')
logger.info(f'Uploading file "{remote_filename}"…')

This is shown to the user, use the local file path slash convention.

Comment thread qfieldcloud_sdk/sdk.py
fields={
"file": (
str(remote_filename),
str(remote_filename_posix),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
str(remote_filename_posix),
str(remote_filename),

This is shown to the user, use the local file path slash convention.

Comment thread qfieldcloud_sdk/sdk.py
@@ -1024,14 +1024,14 @@ def cb(monitor: MultipartEncoderMonitor) -> None:
)

if upload_type == FileTransferType.PROJECT:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Either add on the line before the if:

        remote_filename_posix = Path(remote_filename).as_posix()

Or change lines below as:

                url = f"files/{project_id}/{remote_filename.as_posix()}"

Both are fine with me.

@sentry

sentry Bot commented Dec 4, 2026

Copy link
Copy Markdown

Sentry Issue: QFIELDCLOUD-4N1

This branch has not been deployed

No deployments
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.

2 participants