Skip to content

Add API call to download one file #210

Closed

Description

@wonder-sk

Currently, there's no simple way to fetch just one file from a project. There is download_file() API call, but it needs the project to be already downloaded (it is useful just to get older versions of a file).

One could either query MM server API directly, e.g.:

https://app.merginmaps.com/v1/project/raw/<workspace>/<project>?file=myfile.gpkg

(with appropriate auth token)

Alternatively, using python with a workaround like this (handles auth stuff):

from mergin import MerginClient
from mergin.utils import save_to_file

mergin_client = MerginClient(...)
res = mergin_client.get('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/v1/project/raw/<workspace>/<project>', data={'file': 'myfile.gpkg'})
save_to_file(res, 'myfile.gpkg')

If we add support for this, maybe we could just update the existing download_file() implementation so that it will accept as the first argument either <workspace>/<project> or it would accept an existing the local directory with a project downloaded already.


No project checkout, download raw file

Activity

  1. MarcelGeo commented on Dec 5, 2024

    @MarcelGeo
    Contributor

    Yeah, this will be useful. There is problem if you call download_file , metadata of project must be there ... you have to call download_project before (:-O) . I think we need to update download_file method to accept project_id instead project_dir . Or create separated method to download file based on project path / id without need to get project_info.

  2. 01mk027 commented on Mar 6, 2025

    @01mk027

    fırst of all i wanna giving many of thanks for this response, but i need to learn something more . in

    client.get('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/v1/project/raw/<workspace>/<project>', data={'file': 'myfile.gpkg'}),
    

    is v1 refers to project version? or version of mergin client api? thanks dear @wonder-sk @MarcelGeo

    and i cant see updated versions of gpkg files (or i may misunderstand something in this case)

    def downloadfile(request):
        try:
            if request.method == "POST":
                namespace = request.data['namespace']
                project_name = request.data['project_name']		
                file_path = request.data['file_path']
                output_filename = file_path
                # res = mergin_client.get('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/v1/project/raw/<workspace>/<project>', data={'file': 'myfile.gpkg'})
                # version = None    
                # Create project directory if not exists
                project_dir = os.path.join('../projects', project_name)
                os.makedirs(project_dir, exist_ok=True)  # exist_ok prevents error if dir exists
                client = mergin.MerginClient(login=request.session["username"], password=request.session["password"])
                # bring latest version
                res = client.get(f'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/v1/project/raw/{namespace}/{project_name}', data = {'file': f'{file_path}'})
                save_to_file(res, f'{project_dir}/{output_filename}')
                return JsonResponse({"res": 'o'})
        except Exception as e:
            # Handle errors and return an error message
            return JsonResponse({"error": str(e)}, status=400)
    

    will this code block help to retrieve recently updated version of specified file? If not so, i need small hint dear @tomasMizera , @wonder-sk , @MarcelGeo

  3. MarcelGeo commented on May 13, 2025

    @MarcelGeo
    Contributor

    @01mk027 sorry for late response. But this v1 reffers to version of public api.

  4. varmar05 commented on Sep 10, 2026

    @varmar05
    Contributor

    This is now implemented within existing download command with extra parameter, e.g.

    mergin download-file test.txt /tmp/test.txt --project my-workspace/my-project --version v1
    
  5. RastoHu commented on Sep 15, 2026

    @RastoHu

    testing ok

  6. added this to the 0.15.0 milestone on Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions