Backend API

Every file you upload to Swell will be retrievable from this endpoint. Files represent uploads to our CDN.

Arguments

id

objectIdauto

Unique identifier for the file

aliases

array of String

An array of alternative names or aliases associated with the file.

chunk_size

intauto

The size of data chunks used during file upload.

content_type

string

The MIME type or content type of the file.

date_created

dateauto

The date and time when the file object was initially created.

date_uploaded

dateauto

The date and time when the file was uploaded.

filename

string

The name of the uploaded file.

height

int

The height dimension of the file, applicable for image files.

length

intauto

The length or size of the file in bytes.

md5

stringauto

The MD5 hash value of the file content.

url

stringauto

The URL providing direct access to the file.

width

int

The width dimension of the file, applicable for image files.

The file model
{
    "length": 6028032,
    "chunkSize": 261120,
    "filename": "image.jpg",
    "content_type": "image/jpeg",
    "date_created": "2024-01-03T09:22:39.192Z",
    "date_uploaded": "2024-01-03T09:22:40.032Z",
    "height": 2075,
    "md5": "ed8b7b4eea7b8d54662b86fd707f09f6",
    "url": "https://cdn.swell.store/6595275fc22a5b00127df144",
    "width": 3130,
    "id": "6595275fc22a5b00127df144"
}

Create a new file. If you wish to generate your own unique ID for the record, it must use BSON ObjectID format for compatibility.


Arguments

content_type

string

The MIME type or content type of the file. Can also be generated automatically based on filename

data

objectrequired

The uploaded file in binary or base64 string

filename

stringrequired

Name of the uploaded file

height

int

The height dimension of the file, only applicable for image files.

width

int

The width dimension of the file, only applicable for image files.

POST/:files
const swell = require('swell-node').init('store-id', 'secret-key');
const fs = require('fs');

const dataStream = fs.readFileSync(`image.png`);

await swell.post('/:files', {
  content_type: "image/jpeg",
  filename: "image.jpg",
  data: {
      $base64: dataStream.toString('base64'),
  },
  width: 1200,
  height: 800
});
Response
{
    "length": 4898,
    "chunkSize": 261120,
    "uploadDate": "2024-01-03T11:31:09.153Z",
    "filename": "some-image.jpg",
    "content_type": "image/jpeg",
    "date_created": "2024-01-03T11:31:09.143Z",
    "date_uploaded": "2024-01-03T11:31:09.158Z",
    "md5": "f082a5c3677bb757e11d738cb6f60624",
    "url": "https://cdn.swell.store/f082a5c3677bb757e11d738cb6f60624/some-image.jpg",
    "id": "6595457d82e01f0012243057"
}

Retrieve an existing file using the ID that was returned when created.


Arguments

id

stringrequired

The id of the file to retrieve.

GET/:files
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/:files/{id}', {
});
The file model
{
    "length": 4898,
    "chunkSize": 261120,
    "uploadDate": "2024-01-03T11:31:09.153Z",
    "filename": "some-image.jpg",
    "content_type": "image/jpeg",
    "date_created": "2024-01-03T11:31:09.143Z",
    "date_uploaded": "2024-01-03T11:31:09.158Z",
    "md5": "f082a5c3677bb757e11d738cb6f60624",
    "url": "https://cdn.swell.store/f082a5c3677bb757e11d738cb6f60624/some-image.jpg",
    "id": "6595457d82e01f0012243057"
}

Updates an existing file using the ID that was returned when created. Updating performs a merge operation. To explicitly override values such as arrays, use the $set operator.


Arguments

id

objectIdauto

Unique identifier for the file

PUT/:files
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.put('/:files/{id}', {
  id: '5c8fb5e1ed2faf8c79da492a',
  width: 1200,
  // use $set to override values
  $set: {
    metadata: {
      ...
    },
  },
});
The file model
{
    "length": 4898,
    "chunkSize": 261120,
    "uploadDate": "2024-01-03T11:31:09.153Z",
    "filename": "some-image.jpg",
    "content_type": "image/jpeg",
    "date_created": "2024-01-03T11:31:09.143Z",
    "date_uploaded": "2024-01-03T11:31:09.158Z",
    "md5": "f082a5c3677bb757e11d738cb6f60624",
    "url": "https://cdn.swell.store/f082a5c3677bb757e11d738cb6f60624/some-image.jpg",
    "id": "6595457d82e01f0012243057"
}

Return a list of files.


Arguments

expand

string

Expand link fields and child collections by using the expand argument.

  • For example, expand=account would return a related customer account if one exists.

When the field represents a collection, you can specify the query limit.

  • For example, expand=variants:10 would return up to 10 records of the variants collection.

See expanding for more details.

fields

string

Returns only the specified fields in the result.

  • For example fields=name,slug would return only the fields name and slug in the response.

Supports nested object and array fields using dot-notation.

  • For example, items.product_id. The product id is always returned.

include

object

Include one or more arbitrary queries in the response which are potentially related to the main query.

See including for more details.

limit

int

Limit the number of records returned, ranging between 1 and 1000. Defaults to 15.

page

int

The page number of results to return given the specified or default limit.

search

string

A text search is performed using the search argument. Searchable fields are defined by the model.

  • For example, search=red would return records containing the word "red" anywhere in the defined text fields.

See searching for more details.

sort

string

Expression to sort results by using a format similar to a SQL sort statement.

  • For example, sort=name asc would return records sorted by name ascending.

See sorting for more details.

where

object

An object with criteria to filter the result.

  • For example, active=true would return records containing a field active with the value true.

It's also possible to use query operators, for example, $eq, $ne, $gt, and more.

See querying for more details.

GET/:files
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/:files', {
  limit: 25,
  page: 1,
});
The file model
[{
    "length": 4898,
    "chunkSize": 261120,
    "uploadDate": "2024-01-03T11:31:09.153Z",
    "filename": "some-image.jpg",
    "content_type": "image/jpeg",
    "date_created": "2024-01-03T11:31:09.143Z",
    "date_uploaded": "2024-01-03T11:31:09.158Z",
    "md5": "f082a5c3677bb757e11d738cb6f60624",
    "url": "https://cdn.swell.store/f082a5c3677bb757e11d738cb6f60624/some-image.jpg",
    "id": "6595457d82e01f0012243057"
},
{
    "length": 4898,
    "chunkSize": 261120,
    "uploadDate": "2024-01-03T11:31:09.153Z",
    "filename": "some-other-image.jpg",
    "content_type": "image/jpeg",
    "date_created": "2024-01-03T11:31:09.143Z",
    "date_uploaded": "2024-01-03T11:31:09.158Z",
    "md5": "f082a5c3677bb757e11d738cb6f60624",
    "url": "https://cdn.swell.store/f082a5c3677bb757e11d738cb6f60624/some-image.jpg",
    "id": "6595457d82e01f0012243057"
},
]

Delete a file.

Arguments

id

objectIdrequired

The id of the file you wish to delete.


DELETE/:files
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.delete('/:files/{id}', {
  id: '5c8fb5e1ed2faf8c79da492a',
});
The file model
{
    "length": 4898,
    "chunkSize": 261120,
    "uploadDate": "2024-01-03T11:31:09.153Z",
    "filename": "some-image.jpg",
    "content_type": "image/jpeg",
    "date_created": "2024-01-03T11:31:09.143Z",
    "date_uploaded": "2024-01-03T11:31:09.158Z",
    "md5": "f082a5c3677bb757e11d738cb6f60624",
    "url": "https://cdn.swell.store/f082a5c3677bb757e11d738cb6f60624/some-image.jpg",
    "id": "6595457d82e01f0012243057"
},