Files

Files controller allows to upload and download files and folders, query file lists and metadata from the Biomed platform.

Get more information about the Files API here

Get path

The following code retrieves the metadata of a file with the given its biomed file id.

from genomcore.client import GenomcoreApiClient
api = GenomcoreApiClient(token="A_VALID_TOKEN", refresh_token="A_VALID_REFRESH_TOKEN")

data_path = api.files.get(1969539).path

Get file ID

Get a file ID from a path providing the project ID and the path of the file as a filter.

f = {"idproject": 151, "search": "test_regex_download_extensions/compression-no/biomed-1.0.0.tar"}
filtered_files = api.files.filter(filters=f)
print(filtered_files[0].iddata)

Get list of files

The following code search and provides a list of files in a folder.

f = {
        "parent": "aParentFolder",
        "search": "test_regex_download_extensions/compression-no/biomed-1.0.0.tar",
        "orderDirection": "DESC", #DES (descendant) or ASC (ascendant)
        "orderBy": "updated"
    }
filtered_files = api.files.filter_kube(filters=f)

Get metadata

Get metadata of a file given a Biomed file path.

Note

Root path must have /

f = {"file": "/example_path/example_file.txt"}
file_metadata = api.files.get_metadata(filters=f)
file_iddata = file_metadata.iddata

Get public URL

Biomed provides a public URL to download files/folders with an optional expiration time in seconds. Default is 7200 seconds (2 hours).

public_url = api.files.get_public_url(
    iddata=1969539,
    ttl_in_seconds=14400
)

Download

Download a file or a folder from Biomed given its ID into a local path.

downloaded_data = api.files.download(
    iddata=1969539,
    local_dir="/path/to/download/file"
)

The method can also download multiple IDs and check specific file extensions.

downloaded_data = api.files.download(
    iddata=[1969541, 1969626],
    local_dir="/path/to/download/file",
    allowed_extensions=["tar", "sh", "pdf"],
    allowed_secondary_extensions=["gz", "gz", "gz"]
)

Upload

Upload a file or a folder to the Biomed project defined in the token. The LocalData object is necessary. By default the method will rename the file if it exists.

from genomcore.client import GenomcoreApiClient
from genomcore.models.data import LocalData

api = GenomcoreApiClient(token="A_VALID_TOKEN", refresh_token="A_VALID_REFRESH_TOKEN")


ldata = LocalData(
    path='/target/remote/path/to/file.txt',
    local_path='localfile.txt'
)
uploaded_data = api.files.upload(ldata)

If the file exists, the method will overwrite it if the overwrite action is set.

uploaded_data = api.files.upload(data=ldata, action="overwrite")

Or it can be set to non-action to do nothing.

uploaded_data = api.files.upload(data=ldata, action="non-action")

Delete

Delete a file or a folder from Biomed given its ID.

removed_file = api.files.delete(123456789)

Move

Move file or directory into other directory

Note

if yours iddata star with ‘g’ will be remove

r=api.files.move(src='672bb3edf5dbb80a2a48dad2',dst='g679b4f1e0050f1dcdb09cd4f')

is_dir

Check if your iddata or path is a directory

Note

if yours iddata star with ‘g’ will be remove.

Warning

You only can use or path or iddata.

r=api.files.is_dir(iddata='679b4f1e0050f1dcdb09cd4f')

r=api.files.is_dir(path='path to file')

create_folder

Create a folder in biomed

r=api.files.create_folder("padres/fake")

Note

Create intermediate directories