How to Replace a File Without Changing Its Link
Learn how to update or swap an uploaded file on X02 while keeping the exact same URL and folder settings. Includes simple visual dashboard steps and developer REST API references.
By X02 Team · · Tutorial, File Management, API, Productivity, Developer Tools
We've all been there: you upload a screenshot, publish a guide, send out a PDF report, or post an image link to Discord and Twitter—only to notice a glaring typo, an outdated price tag, or an old UI mockup five minutes later.
On traditional image hosts, fixing this is painful. You have to delete the file, re-upload the new version, get a completely new URL, and then manually edit every tweet, forum post, GitHub readme, or document where the old link was shared. If you don't control the place where the link was posted, you're stuck with a broken link.
X02 solves this with In-Place File Replacement. You can swap the underlying file anytime while keeping the exact same public URL, folder placement, and privacy settings.
[!TIP] Quick Navigation:
Part 1: The Easy Guide (For Everyone)
You don't need any technical skills to replace a file. You can do it in two clicks directly from your personal dashboard.
What Happens When You Replace a File?
- Your link stays identical: Any existing links (
https://x02.me/i/yourfile.png) or custom subdomain links (https://yourname.x02.me/i/yourfile.png) show your new content. X02 clears its own saved copy right away; a browser or an app that saved the old image can take longer (see Still Seeing the Old Image?). - Metadata stays intact: The file's creation date is preserved.
- Folder & privacy settings don't change: If the file was in a specific folder or password-protected album, it stays right where you organized it.
- Old content is permanently erased: The previous version is completely overwritten in storage.
Step-by-Step: Replacing a File from the Dashboard
| Where to Go | Direct Link | Action |
|---|---|---|
Dashboard Gallery [Hover File Card] |
Open Dashboard Gallery | Click Replace (Swap Icon) |
- Log in to your account at x02.me and go to your Dashboard.
- Find the file you want to update in your Gallery.
- Hover over the file card and click the Replace button (or click the file to open the full preview modal and select Replace from the menu).
- Select your new file from your computer.
- Confirm the swap.
That's it! Once the upload finishes, anyone opening your original link will see the new version (a browser that saved the old one may need a hard refresh, see Still Seeing the Old Image?).
[!TIP] Power-User Shortcut: If you replace files frequently, you can turn on "Bypass Confirmation" in your gallery settings to replace files immediately with a single click.
Common Everyday Use Cases
- Discord & Social Media Announcements: Fix mistakes in posted event flyers or schedules without deleting and re-sending messages.
- Documentation & Readmes: Update software screenshots in GitHub readmes without having to commit new image links to Git history.
- Resumes & Client Documents: Update your portfolio or PDF resume while keeping the link you sent to hiring managers active.
- Live Product Banners: Swap promotional graphics on websites or forums without editing HTML embed tags.
Still Seeing the Old Image?
Replacing a file changes it on X02 straight away. The old picture can still show up for a while in two places that X02 does not control:
- Your browser. A browser reuses a picture it has already opened, for up to an hour. Press
Ctrl + F5(Cmd + Shift + Ron a Mac) to reload the page without the saved copy. - Other sites and apps. Discord, forums, chat apps and some websites keep their own copy of the images they show, and X02 cannot clear those. To them, a link with a new ending is a new picture, so add one to the link wherever you use it:
https://x02.me/i/yourfile.png?v=2
X02 ignores everything after the ?, so the link still opens the same file. Change the number each time you replace the file (?v=3, ?v=4, and so on).
Part 2: The Developer & Power User Guide
For developers building automated pipelines, release scripts, or dynamic assets, X02 exposes an in-place replacement endpoint over REST API.
1. How Replacement Operates Under the Hood
When you perform an in-place replacement:
- Object Key Persistence: Rather than generating a new random UUID or slug, the backend retrieves the file's existing storage key (
r2Keyor disk path) and overwrites the binary buffer directly. - Staged Upload: The new file is streamed to a temporary key in storage first, then copied over the live object inside storage. A failed upload never leaves you with a half-replaced file. Replacements are held to the same size and storage limits as uploads, and the same rules about what you may host apply to them.
- Database Metadata Delta: The database recalculates the file size, hash (
SHA-256), and MIME type, updating your account's storage usage delta while preserving the original upload timestamp. - Cache Control & Edge Purging: Right after the swap, X02 asks Cloudflare to drop its saved copy of the file at every address it is served from (
x02.me, your subdomain, your custom domain). The replaced file is stored withpublic, max-age=0, s-maxage=31536000, must-revalidate, so from then on browsers check back with X02 each time instead of reusing a saved copy. A file that has never been replaced carriesmax-age=3600, so a browser that opened the old version can keep it for up to an hour, and caches outside X02 (Discord, forums, chat apps) keep their own copies. See Still Seeing the Old Image?.
2. Replacing a File via cURL (Terminal)
Send a PATCH request to /api/user/images/:filename/replace with your API key:
curl -X PATCH "https://x02.me/api/user/images/ABCD123.png/replace" \
-H "x-api-key: YOUR_X02_API_KEY" \
-F "file=@/path/to/new-graphic.png"
Successful JSON Response:
{
"success": true,
"message": "File replaced successfully",
"data": {
"filename": "ABCD123.png",
"url": "https://x02.me/i/ABCD123.png",
"mimeType": "image/png",
"sizeBytes": 184520,
"oldSizeBytes": 201334,
"updatedAt": "2026-09-01T16:00:00.000Z"
}
}
3. Replacing a File in JavaScript / TypeScript (Node.js)
Automate asset replacements in build scripts or continuous integration workflows:
import fs from "fs";
async function replaceHostedFile(filename: string, newFilePath: string, apiKey: string) {
const formData = new FormData();
const fileBuffer = fs.readFileSync(newFilePath);
formData.append("file", new Blob([fileBuffer]), filename);
const response = await fetch(`https://x02.me/api/user/images/${filename}/replace`, {
method: "PATCH",
headers: {
"x-api-key": apiKey,
"Accept": "application/json",
},
body: formData,
});
if (!response.ok) {
const error = await response.json();
throw new Error(`Failed to replace file: ${error.error || response.statusText}`);
}
const result = await response.json();
console.log("File successfully replaced at:", result.data.url);
return result;
}
// Example usage
replaceHostedFile("banner_q3.png", "./assets/banner_q3_final.png", "YOUR_API_KEY")
.catch(console.error);
4. Replacing a File in Python
A clean Python automation script using requests:
import requests
def replace_file(filename: str, new_file_path: str, api_key: str):
url = f"https://x02.me/api/user/images/{filename}/replace"
headers = {
"x-api-key": api_key,
"Accept": "application/json"
}
with open(new_file_path, "rb") as f:
files = {"file": f}
response = requests.patch(url, headers=headers, files=files)
if response.status_code == 200:
data = response.json()
print(f"Success! File replaced at: {data['data']['url']}")
return data
else:
print(f"Error ({response.status_code}):", response.text)
response.raise_for_status()
# Example usage
replace_file("test-build.zip", "./dist/test-build-v2.zip", "YOUR_API_KEY")
5. Replacing Files from a Shell Script
The same endpoint works from a one-liner, which is handy in a deploy step or a cron job that keeps a hosted asset current:
curl -X PATCH "https://up.x02.me/api/user/images/ABCD123.png/replace" -H "x-api-key: YOUR_API_KEY" -F "file=@./updated_screenshot.png"
Best Practices & Tips
| Tip | Why It Matters |
|---|---|
| Match Format When Possible | While you can swap a .png for another .png, keeping the file extension consistent prevents client-side rendering issues with static image tags. |
| Check Storage Limits | If the replacement file is significantly larger than the old one, ensure your account has sufficient quota to cover the size difference. |
| Give Caches a Moment | X02 clears its own saved copy right after the swap, and that takes a moment to reach every edge location. Browsers (up to an hour) and other sites keep their own copies longer: use a hard refresh (Ctrl + F5 or Cmd + Shift + R) or add ?v=2 to the link. |
Next Steps & Related Tutorials
| What to learn next | Guide Link |
|---|---|
| Rename files to clean URLs | How to Rename Your Uploaded Files |
| Organize uploads into custom folders | How to Organize Files with Folders |
| Connect ShareX for 1-second captures | How to Integrate ShareX with X02 |
| Explore all upload channels | How to Upload Files to X02 |