Backend API
Every file you upload to Swell will be retrievable from this endpoint. Files represent uploads to our CDN.
Arguments
id
objectIdautoUnique identifier for the file
aliases
array of StringAn array of alternative names or aliases associated with the file.
chunk_size
intautoThe size of data chunks used during file upload.
content_type
stringThe MIME type or content type of the file.
date_created
dateautoThe date and time when the file object was initially created.
date_uploaded
dateautoThe date and time when the file was uploaded.
filename
stringThe name of the uploaded file.
height
intThe height dimension of the file, applicable for image files.
length
intautoThe length or size of the file in bytes.
md5
stringautoThe MD5 hash value of the file content.
url
stringautoThe URL providing direct access to the file.
width
intThe 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
stringThe MIME type or content type of the file. Can also be generated automatically based on filename
data
objectrequiredThe uploaded file in binary or base64 string
data.$binary
stringBinary encoded file
data.$base64
stringBase64 encoded file
filename
stringrequiredName of the uploaded file
height
intThe height dimension of the file, only applicable for image files.
width
intThe width dimension of the file, only applicable for image 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
stringrequiredThe id of the file to retrieve.
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
objectIdautoUnique identifier for the file
aliases
array of StringAn array of alternative names or aliases associated with the file.
chunk_size
intautoThe size of data chunks used during file upload.
content_type
stringThe MIME type or content type of the file.
date_created
dateautoThe date and time when the file object was initially created.
date_uploaded
dateautoThe date and time when the file was uploaded.
filename
stringThe name of the uploaded file.
height
intThe height dimension of the file, applicable for image files.
length
intautoThe length or size of the file in bytes.
md5
stringautoThe MD5 hash value of the file content.
url
stringautoThe URL providing direct access to the file.
width
intThe width dimension of the file, applicable for image 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
stringExpand 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
stringReturns 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
objectInclude one or more arbitrary queries in the response which are potentially related to the main query.
See including for more details.
limit
intLimit the number of records returned, ranging between 1 and 1000. Defaults to 15.
page
intThe page number of results to return given the specified or default limit.
search
stringA 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
stringExpression 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
objectAn 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.
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
objectIdrequiredThe id of the file you wish to delete.
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"
},