Skip to content

Import files from cloud storage

files.import_from_cloud(FileImportFromCloudParams**kwargs) -> FileImportFromCloudResponse
POST/v5/files/cloud_imports

Register files that already exist in cloud blob storage as file records, in one batch.

Unlike upload, this transfers no bytes: each entry references an existing object by its container/bucket, filepath, filename, and MIME type, and only a metadata record pointing at that object is created. Files are imported independently and the response reports a per-file status. The response is 200 when every import succeeds and 207 when results are mixed, with each result marked SUCCESS or a failure reason (file does not exist, invalid permissions, or unknown error). Failed entries carry only the submitted filename and MIME type rather than a full file record.

ParametersExpand Collapse
files: Iterable[File]

List of files to import from cloud storage

container: str

The cloud storage container/bucket name

file_type: str

The MIME type of the file

filename: str

The name of the file

filepath: str

The path to the file within the container

x_project_id: Optional[str]
ReturnsExpand Collapse
class FileImportFromCloudResponse: …
results: List[Result]

Results for each file import attempt

file: ResultFile

The file object (full File for success, minimal _FailedFile for failures)

One of the following:
class SGPFile: …
id: str

The unique identifier of the entity.

created_at: datetime

The date and time when the entity was created in ISO format.

formatdate-time
created_by: Identity

The identity that created the entity.

id: str
type: Literal["user", "service_account"]
One of the following:
"user"
"service_account"
object: Optional[Literal["identity"]]
filename: str
md5_checksum: str
mime_type: str
size: int
duration_seconds: Optional[int]
object: Optional[Literal["file"]]
tags: Optional[Dict[str, object]]
class ResultFile_FailedFile: …

Minimal file representation for failed uploads containing only essential information.

filename: str

The original filename from the request

mime_type: str

The original MIME type from the request

object: Optional[Literal["failed_file"]]
status: Literal["SUCCESS", "FAILED_FILE_DOES_NOT_EXIST", "FAILED_INVALID_PERMISSIONS", "FAILED_UNKNOWN_ERROR"]

The status of the upload attempt

One of the following:
"SUCCESS"
"FAILED_FILE_DOES_NOT_EXIST"
"FAILED_INVALID_PERMISSIONS"
"FAILED_UNKNOWN_ERROR"

Import files from cloud storage

import os
from scale_gp_beta import SGPClient

client = SGPClient(
    api_key=os.environ.get("SGP_API_KEY"),  # This is the default and can be omitted
)
response = client.files.import_from_cloud(
    files=[{
        "container": "container",
        "file_type": "file_type",
        "filename": "filename",
        "filepath": "filepath",
    }],
)
print(response.results)
{
  "results": [
    {
      "file": {
        "id": "id",
        "created_at": "2019-12-27T18:11:19.117Z",
        "created_by": {
          "id": "id",
          "type": "user",
          "object": "identity"
        },
        "filename": "filename",
        "md5_checksum": "md5_checksum",
        "mime_type": "mime_type",
        "size": 0,
        "duration_seconds": 0,
        "object": "file",
        "tags": {
          "foo": "bar"
        }
      },
      "status": "SUCCESS"
    }
  ]
}
Returns Examples
{
  "results": [
    {
      "file": {
        "id": "id",
        "created_at": "2019-12-27T18:11:19.117Z",
        "created_by": {
          "id": "id",
          "type": "user",
          "object": "identity"
        },
        "filename": "filename",
        "md5_checksum": "md5_checksum",
        "mime_type": "mime_type",
        "size": 0,
        "duration_seconds": 0,
        "object": "file",
        "tags": {
          "foo": "bar"
        }
      },
      "status": "SUCCESS"
    }
  ]
}