# Create a file

Source: https://developers.swell.is/backend-api/files/create-a-file

Create a new file.

> **Tip:** Note: The maximum size for uploading files using the Files API is **10 Megabytes**.

## Arguments

- `content_type` (string): The MIME type or content type of the file. If omitted, it's detected automatically from the file data.
- `data` (object, required): The uploaded file in binary or base64 string
  - `$binary` (string): Binary encoded file
  - `$base64` (string): Base64 encoded file
- `filename` (string): 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.
- `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.

## Example request

`POST /:files`

**cURL**

```sh
$ curl https://api.swell.store/:files \
  -u store-id:secret-key \
  -d content_type=image/jpeg \
  -d filename=image.jpg \
  -d width=1200 \
  -d height=800 \
  -d data[$base64]="/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsL"
```

**Node**

```javascript
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,
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$imagedata = file_get_contents('/path/to/image.jpg');

$swell->post('/:files', [
  'content_type' => 'image/jpeg',
  'filename' => 'image.jpg',
  'width' => 1200,
  'height' => 800,
  'data' => [
    '$base64' => base64_encode($imagedata),
  ],
]);
```

## Example response

```json
{
    "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"
}
```
