---
title: "Replace file"
method: PUT
path: "/files/{id}"
tags: ["files"]
---

# Replace file

`PUT /files/{id}`

Replace an existing file with new content while preserving the file ID. The operation follows these steps:
1. The isUploaded flag is set to false to mark the file as being updated
2. The file content is replaced in the storage backend
3. File metadata is updated (size, mime-type, isUploaded, etc.)

Each step is atomic, but if a step fails, previous steps will not be automatically rolled back.

## Path parameters

- `id` string, required

## Response `200`

File successfully replaced

- FileMetadata — Comprehensive metadata information about a file in storage.
  - `id` string, required — Unique identifier for the file.
  - `name` string, required — Name of the file including extension.
  - `size` integer, required — Size of the file in bytes.
  - `bucketId` string, required — ID of the bucket containing the file.
  - `etag` string, required — Entity tag for cache validation.
  - `createdAt` string, date-time, required — Timestamp when the file was created.
  - `updatedAt` string, date-time, required — Timestamp when the file was last updated.
  - `isUploaded` boolean, required — Whether the file has been successfully uploaded.
  - `mimeType` string, required — MIME type of the file.
  - `uploadedByUserId` string — ID of the user who uploaded the file.
  - `metadata` object — Custom metadata associated with the file.

## Other responses

- `default` — Error occurred during file replacement

---

[API](https://skmtc.dev/nhost/apis/nhost-storage-api.md) · [All operations](https://skmtc.dev/nhost/apis/nhost-storage-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/nhost/nhost-storage-api/revisions/97295913b74e/schema)
