File Size Mismatch Error
What the file size mismatch error means and how to fix it
File Size Mismatch Error
If you see a "file size mismatch" error, it means the actual uploaded file size doesn't match the size you declared.
What This Means
When you request a presigned upload URL, you provide a fileSize parameter. When the upload completes, we verify that the actual file size matches what you declared. This prevents:
Common Causes
1. Incorrect Content-Length Header
The most common cause is providing the wrong Content-Length header during the upload:
# ❌ WRONG - hardcoded size doesn't match file
curl -X PUT "$UPLOAD_URL" \
-H "Content-Type: video/mp4" \
-H "Content-Length: 1000000" \
--data-binary @video.mp4
# ✅ CORRECT - let curl calculate the size
curl -X PUT "$UPLOAD_URL" \
-H "Content-Type: video/mp4" \
--data-binary @video.mp4
2. File Modified After Getting Presigned URL
If the file is modified between requesting the presigned URL and uploading, the sizes won't match:
// ❌ WRONG - file could change between these calls
const fileSize = file.size
const { uploadUrl } = await getPresignedUrl({ fileSize })
// ... time passes, file is modified ...
await uploadFile(uploadUrl, file) // Size mismatch!
// ✅ CORRECT - get size right before upload
const fileSize = file.size
const { uploadUrl } = await getPresignedUrl({ fileSize })
await uploadFile(uploadUrl, file) // Immediately upload
3. Compression or Transformation Applied
If you compress or transform the file after getting the presigned URL, the size will change:
// ❌ WRONG - file is compressed after size check
const originalSize = file.size
const { uploadUrl } = await getPresignedUrl({ fileSize: originalSize })
const compressedFile = await compressVideo(file)
await uploadFile(uploadUrl, compressedFile) // Size changed!
// ✅ CORRECT - compress first, then get size
const compressedFile = await compressVideo(file)
const fileSize = compressedFile.size
const { uploadUrl } = await getPresignedUrl({ fileSize })
await uploadFile(uploadUrl, compressedFile)
How to Fix
Example: Correct Upload Flow
// 1. Get file size
const file = document.getElementById('fileInput').files[0]
const fileSize = file.size
// 2. Request presigned URL with exact size
const response = await fetch('https://api.ffmpeg-micro.com/v1/upload/presigned-url', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
filename: file.name,
contentType: file.type,
fileSize: fileSize
})
})
const { uploadUrl, filename } = await response.json()
// 3. Upload immediately (don't set Content-Length)
await fetch(uploadUrl, {
method: 'PUT',
headers: {
'Content-Type': file.type
},
body: file
})
// 4. Confirm upload with same size
await fetch('https://api.ffmpeg-micro.com/v1/upload/confirm', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
filename: filename,
fileSize: fileSize
})
})
Still Having Issues?
If you're still seeing file size mismatches after following these steps, contact support at javid@ffmpeg-micro.com with:
Can't find what you're looking for?