Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeCrop property problem #274

Closed
Valtas opened this issue Jan 24, 2024 · 5 comments
Closed

beforeCrop property problem #274

Valtas opened this issue Jan 24, 2024 · 5 comments

Comments

@Valtas
Copy link

Valtas commented Jan 24, 2024

Codesandbox https://codesandbox.io/p/sandbox/antd-img-crop-beforecrop-problem-wftx6c

Open console
Upload a file larger than 2 MB
Called beforeUpload

It is expected that beforeUpload will not be called. This behavior was present in earlier versions of antd-img-crop

@nanxiaobei
Copy link
Owner

nanxiaobei commented Jan 24, 2024

yes, the logic has changed,
beforeCrop is only used to determine whether to open the crop modal,
beforeUpload is used to determine whether to upload file.

@Valtas
Copy link
Author

Valtas commented Jan 24, 2024

because of this I get a situation where I can’t prohibit files at the img-crop stage

beforeCrop - I check that the file is acceptable for img-crop. The file is invalid but calls beforeUpload, although upload is prohibited...

in beforeUpload I also do a protection check, and I get a double check and a double error message..

@nanxiaobei
Copy link
Owner

yes, this may require check twice.
but there are still some usage scenarios,
they hope to crop some images, and upload other images directly.
it's difficult to balance.

for your scene, I think this can be done:

const canUpload = useRef(false)
const beforeCrop = (file) => {
  // do check
}

beforeCrop={(file) => {
  canUpload.current = beforeCrop(file)
  return canUpload.current
}}
beforeUpload={() => canUpload.current}

@Valtas
Copy link
Author

Valtas commented Jan 24, 2024

Yes, there are options to handle the case. It was great before this)

Perhaps all situations would be resolved if beforeCrop returned an enum value that either completely stopped or skipped the crop stage

enum.SKIP
enum.STOP ...

@nanxiaobei
Copy link
Owner

thx, will consider that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants