receipt-form: Omit empty uploaded file

If there is no file to be uploaded, then we must not send the value of
the `photo` file input.  Doing so causes two files to be uploaded, the
first one being a zero-byte file with no name, and the second one being
the one we captured from the camera.  The server only uses the first
uploaded file if there are multiple, so the correct file is never used.
This commit is contained in:
2025-03-09 21:04:15 -05:00
parent e4ddfbd025
commit e2b14ecf10

View File

@@ -26,9 +26,12 @@ form.addEventListener("submit", async (evt) => {
evt.preventDefault();
btnSubmit.loading = true;
const data = new FormData(form);
const blob = await cameraInput.getBlob();
if (blob) {
data.append("photo", blob, "photo.jpg");
if (!inpImage.files?.length) {
data.delete("photo");
const blob = await cameraInput.getBlob();
if (blob) {
data.append("photo", blob, "photo.jpg");
}
}
let r: Response;
try {