diff --git a/src/client/components/forms/field-types/Upload/index.js b/src/client/components/forms/field-types/Upload/index.js index a5b846c3e7..c2660f8c9b 100644 --- a/src/client/components/forms/field-types/Upload/index.js +++ b/src/client/components/forms/field-types/Upload/index.js @@ -19,6 +19,7 @@ const baseClass = 'upload'; const Upload = (props) => { const { toggle } = useModal(); const [internalValue, setInternalValue] = useState(undefined); + const [missingFile, setMissingFile] = useState(false); const { collections, serverURL, routes: { api } } = useConfig(); const { @@ -75,12 +76,16 @@ const Upload = (props) => { if (response.ok) { const json = await response.json(); setInternalValue(json); + } else { + setInternalValue(undefined); + setValue(null); + setMissingFile(true); } }; fetchFile(); } - }, [value, setInternalValue, relationTo, api, serverURL]); + }, [value, setInternalValue, relationTo, api, serverURL, setValue]); return (
{ /> {collection?.upload && ( - {internalValue && ( + {(internalValue && !missingFile) && ( { }} /> )} - {!value && ( + {(!value || missingFile) && (