Skip to content

Conversation

@suricactus
Copy link
Collaborator

Use urlparse to do it properly.

QFieldCloud expects trailing slashes in the resource URLs. We add them in a very naive way now, just checking the string. This causes issues if the URL has querystring, hash or other elements.

Supercedes #82 .

Use urlparse to do it properly.

QFieldCloud expects trailing slashes in the resource URLs.
We add them in a very naive way now, just checking the string.
This causes issues if the URL has querystring, hash or other elements.
@duke-nyuki
Copy link
Collaborator

@psclcnrd
Copy link

psclcnrd commented Aug 5, 2025

Hello. I don't sure the trailling slash is deleted in case of url with a parameter.
An example:
An error occurred: Requested "https://app.qfield.cloud/api/v1/files/82af6b6f-70dd-41a5-80ec-7edc53758c56/aerialsurveyhelicoptertrack.gpkg/?version=fb13e2ad-6316-4ed7-adf9-91cef96cc495/" and got "400 Bad Request"
Without the '/' at the end, this request work fine.

@suricactus
Copy link
Collaborator Author

Would you mind writing code to reproduce the error you are talking about and what are your concerns that this PR will not address them?

@psclcnrd
Copy link

psclcnrd commented Aug 5, 2025

This code don't work because the sdk add a '/' t the end of the URL.

def download_oldest_file_by_name(self, filename, dest):
"""
Download the oldest file into a destination folder

    :param filename: The name of the file to download
    :type filename: str
    :param dest: Destination for downloaded file
    :return:
    """
    version = self.oldest_version(filename)
    self._logger.info(f"Download file for feature {filename}.")
    self._connection.qfieldcloud_connection.download_file(self._connection.project_id,   
                                                         download_type=FileTransferType.PROJECT,
                                                          local_filename=Path(dest),
                                                          remote_filename=Path(f"{filename}?version={version.version_id}"),
                                                          show_progress=False)

That raised a 400 error.
The '/' at end can be added only if there's no parameter like this code, with the parameter '?version='.

And the problem also exist when I want to download a media file.

@suricactus
Copy link
Collaborator Author

suricactus commented Aug 5, 2025

I am not sure if I follow, I am sorry.

You have pasted some code which appears to be from some other software. This is fine, I see you are trying to download a specific file version.

Assuming you have a global QFIELDCLOUD_TOKEN envvar, the minimal code to reproduce would be:

# given the variables: project_id, dest, filename, version_id

from qfieldcloud_sdk import sdk
c = sdk.Client()
c.download_file(
	project_id,
	download_type=sdk.FileTransferType.PROJECT,
	local_filename=Path(dest),
	remote_filename=Path(f"{filename}?version={version_id}"),
	show_progress=False,
)

But I don't get if this particular PR works for you or it doesn't? Have you tried it?

@suricactus
Copy link
Collaborator Author

suricactus commented Aug 5, 2025

Also, we will be happy to receive a PR that adds the version_id as a new optional parameter to download_file, instead of hacking it in the remote_filename parameter.

@psclcnrd
Copy link

psclcnrd commented Aug 5, 2025

Ok, sorry, I have tested the method add_trailling_slash_to_url, and this is fine. I didn't quite understand the role of the 2 parsing functions. My apologies...

@suricactus suricactus merged commit 564a10c into master Aug 5, 2025
8 checks passed
@suricactus suricactus deleted the QF-6452-trailing-slash branch August 5, 2025 13:37
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