Backend API
Create a new file.
👉
Note: The maximum size for uploading files using the Files API is 10 Megabytes.
Arguments
content_typestring
The MIME type or content type of the file. If omitted, it's detected automatically from the file data.
dataobjectrequired
The uploaded file in binary or base64 string
data.$binarystring
Binary encoded file
data.$base64string
Base64 encoded file
filenamestring
Name of the uploaded file. If omitted, a filename is generated in the format file-{id}.{ext}, using the extension that matches the file's content type. When the content type can't be determined — as with plain text data — no filename is generated.
heightint
The height dimension of the file, only applicable for image files.
widthint
The width dimension of the file, only applicable for image files.
POST/:files
const { swell } = require('swell-node');
const fs = require('fs');
swell.init('store-id', 'secret-key');
const fileData = fs.readFileSync('image.jpg');
await swell.post('/:files', {
content_type: 'image/jpeg',
filename: 'image.jpg',
data: {
$base64: fileData.toString('base64'),
},
width: 1200,
height: 800,
});Response
{
"length": 4898,
"chunkSize": 261120,
"uploadDate": "2024-01-03T11:31:09.153Z",
"filename": "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/image.jpg",
"width": 1200,
"height": 800,
"id": "6595457d82e01f0012243057"
}