Replace Asset File

Replaces the existing file of a specified asset with a new file upload. This operation keeps the same asset ID but updates the stored content and metadata such as size and type. Authentication is required to ensure the user’s permission.

POST

POST

https://api.cortado.com/v1/assets/{asset_id}/replace

Request

Accepts multipart/form-data with the new file under the file field. The asset ID is passed in the path parameter.

Body Parameters

Parameters

Type

Description

file

file

New file to replace the asset’s existing file

Based on the steps above, your code might look something like this. It brings together the key concepts covered — from setup and configuration to routing, authentication, or event handling. Feel free to adapt it to suit your specific use case.

main.ts

import axios from 'axios';

async function replaceAssetFile(assetId: string, file: File) {
  const formData = new FormData();
  formData.append('file', file);

  const res = await axios.post(`https://api.cortado.com/v1/assets/${assetId}/replace`, formData, {
    headers: {
      Authorization: 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'multipart/form-data',
    },
  });

  return res.data;
}

main.ts

import axios from 'axios';

async function replaceAssetFile(assetId: string, file: File) {
  const formData = new FormData();
  formData.append('file', file);

  const res = await axios.post(`https://api.cortado.com/v1/assets/${assetId}/replace`, formData, {
    headers: {
      Authorization: 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'multipart/form-data',
    },
  });

  return res.data;
}

main.ts

import axios from 'axios';

async function replaceAssetFile(assetId: string, file: File) {
  const formData = new FormData();
  formData.append('file', file);

  const res = await axios.post(`https://api.cortado.com/v1/assets/${assetId}/replace`, formData, {
    headers: {
      Authorization: 'Bearer YOUR_ACCESS_TOKEN',
      'Content-Type': 'multipart/form-data',
    },
  });

  return res.data;
}

Response

Returns updated asset metadata including new size, type, and upload timestamp. If the asset ID is invalid or unauthorized, returns an error.

main.ts

{
  "id": "asset_64f1b2cc",
  "type": "image/jpeg",
  "size": 254312,
  "url": "https://cdn.cortado.com/assets/asset_64f1b2cc.jpg",
  "uploadedAt": "2025-07-14T15:30:00Z"
}

main.ts

{
  "id": "asset_64f1b2cc",
  "type": "image/jpeg",
  "size": 254312,
  "url": "https://cdn.cortado.com/assets/asset_64f1b2cc.jpg",
  "uploadedAt": "2025-07-14T15:30:00Z"
}

main.ts

{
  "id": "asset_64f1b2cc",
  "type": "image/jpeg",
  "size": 254312,
  "url": "https://cdn.cortado.com/assets/asset_64f1b2cc.jpg",
  "uploadedAt": "2025-07-14T15:30:00Z"
}

Was this helpful?

Dismiss

Was this helpful?

Dismiss

Last updated on

Jul 21, 2025