It usually works great but yesterday a user got an error message that only said, “Ooops! Something went wrong during upload.” She sent me the image and there was nothing unusual about it – it was a 333KB jpeg.
Is there a way I can show a more detailed error message?
I have code in my app that follows the CodePen demo.
My app uses React. I have a component that adds the UploadCare image field:
function Uploader(props) {
const {value, onChange, onUploadComplete, targetId, targetFileName} = props;
useLayoutEffect(() => {
// get a widget instance
var widget = uploadcare.Widget('[id=' + targetId + ']');
// listen to the "upload completed" event
widget.onUploadComplete(function (fileInfo) {
// get CDN URL from file information. Here you can generate a thumbnail using the fie URL, save the URL to DB, and so on.
// console.log(fileInfo.cdnUrl);
onUploadComplete(fileInfo);
});
}, []);
return (
<input type="hidden" role="uploadcare-uploader" name={targetFileName} id={targetId}/>
)
}
This is working fine as is, without a call to widget.onDialogOpen. Will it be okay if I update it like this?
function Uploader(props) {
const {value, onChange, onUploadComplete, targetId, targetFileName} = props;
useLayoutEffect(() => {
// get a widget instance
var widget = uploadcare.Widget('[id=' + targetId + ']');
widget.onDialogOpen((dialog) => {
dialog.fileColl.onAdd.add((file) => {
file.fail((errKind, fileInfo, errInfo) => {
console.error(errInfo);
});
file.done((fileInfo) => {
console.log(fileInfo.cdnUrl);
});
});
});
// listen to the "upload completed" event
widget.onUploadComplete(function (fileInfo) {
// get CDN URL from file information. Here you can generate a thumbnail using the fie URL, save the URL to DB, and so on.
// console.log(fileInfo.cdnUrl);
onUploadComplete(fileInfo);
});
}, []);
return (
<input type="hidden" role="uploadcare-uploader" name={targetFileName} id={targetId}/>
)
}
widget.onUploadComplete(function (fileInfo) {
// get CDN URL from file information. Here you can generate a thumbnail using the fie URL, save the URL to DB, and so on.
// console.log(fileInfo.cdnUrl);
onUploadComplete(fileInfo);
});