Unable to crop image and disable uploading by returning "false" from "beforeUpload"
See original GitHub issueI am using the Upload
component as a local file input and am not using it to actually upload my files. I need to handle the file uploads myself. I am doing this by returning false
from beforeUpload
. However, if I do this while using antd-img-crop
, the cropping functionality does not work.
This is my code:
...
const ImageInput: React.FC<ImageInputProps> = ({ maxCount, onChange }) => {
const handleChange = { ... };
const handleRemove = { ... };
const handlePreview = { ... };
const beforeUpload = () => {
return false;
};
return (
<ImgCrop grid rotate>
<Upload
accept='image/png, image/jpeg'
listType='picture-card'
onChange={handleChange}
onRemove={handleRemove}
onPreview={handlePreview}
maxCount={maxCount}
beforeUpload={beforeUpload}
>
<div>
<Text type='secondary'>
<PlusOutlined />
</Text>
<div style={{ marginTop: 8 }}>
<Text type='secondary'>Upload Image</Text>
</div>
</div>
</Upload>
</ImgCrop>
);
};
export default ImageInput;
The cropping only works if I remove beforeUpload={beforeUpload}
. I’ve tried returning a lot of different things from beforeUpload
, and nothing has worked.
Any ideas? Any help would be greatly appreciated. I took a look a the source code and I think the issue is that on this line it is just rejecting. The newFile
at this point is just being lost. I’m not sure what to do about it, though.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
antd-img-crop - npm
An image cropper for Ant Design Upload. Latest version: 4.5.2, ... Start using antd-img-crop in your project by running `npm i antd-img-crop`.
Read more >action function is required with antd upload control, but I dont ...
Upload files manually after beforeUpload returns false . beforeUpload(file) { const isJPG = file.type === 'image/jpeg' ...
Read more >Upload - Ant Design
Click to upload user's avatar, and validate size and format of picture with beforeUpload . ... Upload files manually after beforeUpload returns false...
Read more >Handling image uploads | Docs - TinyMCE
How to manage asynchronous image uploads. ... If the callback function provided returns false for an image, the image will not be uploaded....
Read more >Uploading and Resizing Images with React: Part 1 - Client Side
During my development experience on a specific project, I was unable to find any good tutorials or guides on how to make a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can write
beforeUpload
in this way:and remove
onChange={onChange}
to updatefileList
manually.There is a problem with this solution. The property called
originFileObj
in added file will be undefined. How can we achieve it because theurl
is base64. Also, it’s not type safe and i get many type errors.