# Update a file

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

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` (objectId, required): The id of the file you wish to update.
- `data` (filedata): File content, base64-encoded when created or updated through the API.
- `filename` (string): The name of the uploaded file.
- `aliases` (array of String): An array of alternative names or aliases associated with the file.
- `metadata` (object): Arbitrary data for storing additional information about the file.
- `private` (boolean): Indicates the file is private and not served publicly from the CDN.
- `width` (int): The width dimension of the file, applicable for image files.
- `height` (int): The height dimension of the file, applicable for image files.

## Example request

`PUT /:files`

**cURL**

```sh
$ curl https://api.swell.store/:files/6595457d82e01f0012243057 \
  -u store-id:secret-key \
  -d width=1200 \
  -X PUT
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.put('/:files/{id}', {
  id: '6595457d82e01f0012243057',
  width: 1200,
  // use $set to override values
  $set: {
    metadata: {
      ...
    },
  },
});
```

**PHP**

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

$swell->put('/:files/{id}', [
  'id' => '6595457d82e01f0012243057',
  'width' => 1200,
  // use $set to override values
  '$set' => {
    'metadata' => [
      ...
    ],
  ],
]);
```

## 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,
    "id": "6595457d82e01f0012243057"
}
```
