Skip to content

Upload file bytes directly

client.files.create(FileCreateParams { file, xProjectID } params, RequestOptionsoptions?): SGPFile { id, created_at, created_by, 7 more }
POST/v5/files

Upload a file’s bytes directly and create a file record.

Send the file as multipart/form-data in the file field; the request body carries the raw bytes, unlike cloud_imports which only references blobs that already exist in cloud storage. The upload is rejected if it exceeds 25 MB; larger or direct-to-storage uploads use a separate upload flow. The server detects the content type from the bytes and rejects content that fails the structural validation for that type. Content is deduplicated by checksum and MIME type, so uploading bytes identical to an existing file reuses the already-stored object instead of storing a second copy. Returns the created file’s metadata.

ParametersExpand Collapse
params: FileCreateParams { file, xProjectID }

Body param

xProjectID?: string

Header param

ReturnsExpand Collapse
SGPFile { id, created_at, created_by, 7 more }
id: string

The unique identifier of the entity.

created_at: string

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

formatdate-time
created_by: Identity { id, type, object }

The identity that created the entity.

id: string
type: "user" | "service_account"
One of the following:
"user"
"service_account"
object?: "identity"
filename: string
md5_checksum: string
mime_type: string
size: number
duration_seconds?: number
object?: "file"
tags?: Record<string, unknown>

Upload file bytes directly

import SGPClient from 'scale-gp';

const client = new SGPClient({
  accountID: 'My Account ID',
  apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});

const sgpFile = await client.files.create({ file: fs.createReadStream('path/to/file') });

console.log(sgpFile.id);
{
  "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"
  }
}
Returns Examples
{
  "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"
  }
}