Skip to content

Import files from cloud storage

client.Files.ImportFromCloud(ctx, params) (*FileImportFromCloudResponse, error)
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
params FileImportFromCloudParams
Files param.Field[[]FileImportFromCloudParamsFile]

Body param: List of files to import from cloud storage

Container string

The cloud storage container/bucket name

FileType string

The MIME type of the file

Filename string

The name of the file

Filepath string

The path to the file within the container

XProjectID param.Field[string]Optional

Header param

ReturnsExpand Collapse
type FileImportFromCloudResponse struct{…}
Results []FileImportFromCloudResponseResult

Results for each file import attempt

File FileImportFromCloudResponseResultFileUnion

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

One of the following:
type SGPFile struct{…}
ID string

The unique identifier of the entity.

CreatedAt Time

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

formatdate-time
CreatedBy Identity

The identity that created the entity.

ID string
Type IdentityType
One of the following:
const IdentityTypeUser IdentityType = "user"
const IdentityTypeServiceAccount IdentityType = "service_account"
Object IdentityObjectOptional
Filename string
Md5Checksum string
MimeType string
Size int64
DurationSeconds int64Optional
Object SGPFileObjectOptional
Tags map[string, any]Optional
type FileImportFromCloudResponseResultFile_FailedFile struct{…}

Minimal file representation for failed uploads containing only essential information.

Filename string

The original filename from the request

MimeType string

The original MIME type from the request

Object stringOptional
Status string

The status of the upload attempt

One of the following:
const FileImportFromCloudResponseResultStatusSuccess FileImportFromCloudResponseResultStatus = "SUCCESS"
const FileImportFromCloudResponseResultStatusFailedFileDoesNotExist FileImportFromCloudResponseResultStatus = "FAILED_FILE_DOES_NOT_EXIST"
const FileImportFromCloudResponseResultStatusFailedInvalidPermissions FileImportFromCloudResponseResultStatus = "FAILED_INVALID_PERMISSIONS"
const FileImportFromCloudResponseResultStatusFailedUnknownError FileImportFromCloudResponseResultStatus = "FAILED_UNKNOWN_ERROR"

Import files from cloud storage

package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  response, err := client.Files.ImportFromCloud(context.TODO(), sgpdev.FileImportFromCloudParams{
    Files: []sgpdev.FileImportFromCloudParamsFile{sgpdev.FileImportFromCloudParamsFile{
      Container: "container",
      FileType: "file_type",
      Filename: "filename",
      Filepath: "filepath",
    }},
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", 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"
    }
  ]
}