Strip Metadata From User Uploads: Photos, Office Files and PDFs
When users upload files to your app, they send more than they can see. A photo can carry the exact GPS position of the user's home. A Word document can carry the author's full name, their company, who edited it last and the folder path on their laptop. A PDF can carry scripts and attached files. If your app shows, shares or forwards uploads, all of that goes along. This guide shows how to clean every upload with the PrivConvert file conversion API, and exactly what each cleaning step removes.
What hides in an ordinary upload
Photos
Phone cameras record EXIF data in every photo: GPS coordinates, the phone model and serial number, and the date and time it was taken. Marketplaces, dating apps, forums and support tools that display user photos as-is publish that information. A single listing photo taken at home can reveal where the seller lives.
Office documents
Word, Excel and PowerPoint files keep the author's name, the last person to edit, the company and manager fields, creation and print dates, total editing time, the template path and custom properties. Embedded images keep their own EXIF. Links to other files can expose local folder names such as C:\Users\jane.smith\Clients\.
PDFs
Beyond the author and the software that made them, PDFs can contain JavaScript, actions that run when the file opens, embedded files and forms that send data somewhere. If your app passes uploaded PDFs to staff or other users, those are a real attack surface.
Three endpoints, one pattern
# Photos: GPS, camera serial, capture time
curl -X POST https://privconvert.com/api/convert/remove-exif \
-H "Authorization: Bearer $PRIVCONVERT_API_KEY" -F "[email protected]" -o photo-clean.jpg
# Word, Excel, PowerPoint: author, company, edit history, file paths
curl -X POST https://privconvert.com/api/convert/remove-doc-metadata \
-H "Authorization: Bearer $PRIVCONVERT_API_KEY" -F "[email protected]" -o report-clean.docx
# PDF: scripts, attachments, auto-run actions and metadata
curl -X POST https://privconvert.com/api/convert/sanitize-pdf \
-H "Authorization: Bearer $PRIVCONVERT_API_KEY" -F "[email protected]" -o form-clean.pdf -D headers.txt Each takes the file in a field called file and returns the cleaned file in the same format (HEIC and AVIF photos come back as JPG, which every browser can show).
Exactly what is removed
| File | Removed | Kept |
|---|---|---|
| Photos (JPG, PNG, WEBP, HEIC, AVIF, GIF) | All EXIF, including GPS, device, serial number and timestamps | Pixels, upright orientation, animation |
| Word, Excel, PowerPoint | Author, last editor, title, subject, keywords, category, dates, revision, company, manager, template, editing time, custom properties, EXIF in embedded images, local file paths in links | All content and formatting |
| JavaScript and auto-run actions, launch and form-submit actions, embedded files, document metadata | Text, images, layout, normal links |
Clean every upload automatically
Pick the endpoint from the file's first bytes, not from its name or the browser's content type, which users and browsers get wrong all the time:
from privconvert import PrivConvert, BadRequestError, UnsupportedTypeError
pc = PrivConvert() # reads PRIVCONVERT_API_KEY
PHOTO_BRANDS = (b"heic", b"heix", b"mif1", b"msf1", b"avif")
def tool_for(data: bytes, name: str) -> str | None:
if data[:4] == b"%PDF":
return "sanitize-pdf"
if (data[:3] == b"\xff\xd8\xff" or data[:8] == b"\x89PNG\r\n\x1a\n"
or data[:6] in (b"GIF87a", b"GIF89a")
or (data[:4] == b"RIFF" and data[8:12] == b"WEBP")
or (data[4:8] == b"ftyp" and data[8:12] in PHOTO_BRANDS)):
return "remove-exif"
# DOCX, XLSX and PPTX are ZIP files; the name tells them apart from other ZIPs
if data[:4] == b"PK\x03\x04" and name.lower().endswith((".docx", ".xlsx", ".pptx")):
return "remove-doc-metadata"
return None
def clean_upload(data: bytes, name: str) -> bytes:
tool = tool_for(data, name)
if tool is None:
return data
try:
result = pc.convert(tool, data, filename=name)
except (BadRequestError, UnsupportedTypeError):
raise ValueError("This file could not be read. Please upload it again.")
if tool == "sanitize-pdf" and result.sanitize_report:
log.info("pdf cleaned", extra=result.sanitize_report)
return result.content Run it as soon as the upload arrives, before the file is stored, so the original never reaches your storage, your backups or your CDN. That is far easier than trying to clean files later.
Use the PDF report
The PDF endpoint tells you what it found, in a small JSON report:
import { PrivConvert } from "privconvert";
const pc = new PrivConvert();
const result = await pc.convert("sanitize-pdf", upload, { filename: "form.pdf" });
console.log(result.sanitizeReport);
// { javascript: 1, metadata_removed: true, clean: false }
await saveToStorage(result.content); A PDF invoice or CV should never contain JavaScript. If the report shows scripts or embedded files on an upload that should be a plain document, it is worth logging, or flagging for a closer look.
Why this matters beyond privacy
- GDPR and data minimisation. Location and device data in uploaded photos is personal data you probably never meant to collect. Not storing it is simpler than protecting it. See file conversion and GDPR processor obligations.
- Security. Removing scripts and attachments from PDFs closes off a common route for malicious documents to reach your staff.
- Trust. Users rarely know what their files reveal. Cleaning uploads protects them without asking them to do anything.
The cleaner itself should not keep a copy
Sending files to a third party to remove private data only makes sense if that party does not store them. PrivConvert processes every file in memory and returns the result in the same response: nothing is written to disk and no copy is kept. Every PDF we return also has the producing software and timestamps removed from its metadata, whichever tool made it.
Cleaning a single file by hand? Use the free EXIF remover, Office metadata remover or PDF sanitizer. For the background on photos, read remove EXIF data before sharing photos.
FAQ
Does removing metadata change how the file looks?
No. Photos keep their pixels and are rotated upright first, so they display the same. Office documents keep all their content and formatting. PDFs keep their text, images, layout and normal links; only active content and hidden information are removed.
What happens to iPhone HEIC photos?
HEIC and AVIF photos are cleaned and returned as JPG, since most browsers cannot display those formats anyway. JPG, PNG and WEBP stay in their own format, and animated GIFs keep their animation.
What does the PDF report contain?
The sanitize endpoint returns a short JSON report in the X-Sanitize-Report header, for example how many scripts and embedded files were removed and whether the file was already clean. The SDKs expose it as sanitize_report or sanitizeReport, so you can log or flag suspicious uploads.
Can metadata be removed from old .doc and .xls files?
The metadata tool works on the modern formats (DOCX, XLSX, PPTX). Convert older files to the modern format first, or to PDF if they only need to be read.
Are the files stored while they are cleaned?
No. Every file is processed in memory and returned in the same response. Nothing is written to disk and no copy is kept.