-
-
Notifications
You must be signed in to change notification settings - Fork 494
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
Improve error message when uploading image without correct extension or mimetype #2211
Improve error message when uploading image without correct extension or mimetype #2211
Conversation
@sarim let's see what github actions says, but on my computer I couldn't make this test fail. |
@jordisala1991 I think your test are passing because resizer / provider etc.. service are mocked in that test file, not real services. Here I just grabbed a random cat pic from imgur and can reproduce the error. |
47c106c
to
c3d697a
Compare
You are right @sarim, but I have just changed the test to not mock anything related to size calculations. Now it is not mocked. I have left the GD implementation of imagine because that's what we are installing on github-actions. But I have tested with: Gd, imagick and gmagick. Those 3 implementations works and produce the same result. We can merge this test because at the end it improves coverage, but as far as I can tell, if there is any issue you need to look at Imagine library, not here. I left this as patch because I have added a fix on a strlen call, but it is only related to stop mocking things we don't own rather than the original bug reported. |
74c2978
to
43008a8
Compare
Now that I take a look at the add media command, do you have the problem only when using the command? did you tried to use the admin panel to upload that image? I think the problem might be because of the usage of this command. |
43008a8
to
fb7c89e
Compare
Finally, it is related directly to the command and how all the flow executes. Now github actions fails with the same error reported. |
fb7c89e
to
7288a03
Compare
You kinda lost me in this complex testing technology. If you would've just run the command from any repo (for example I showed screen from sonata sandbox) you would've encountered the problem. The problem is simple, as I described in my original issue. The problem was NOT in sonata v2. I upgraded a symfony2+sonata2 project to symfony 5 + sonata 4 and encountered this problem. Let me reiterate : From Usage doc $media = new Media();
$media->setBinaryContent(PATH TO IMAGE FILE);
$media->setContext('default');
$media->setProviderName('sonata.media.provider.image');
/** @var Sonata\MediaBundle\Model\MediaManagerInterface $mediaManager */
$mediaManager->save($media); This is the way to create a new media. I was creating image using this code after a form submit, as you know, php saves uploaded files in Now the error is simple and easy to reproduce, as the media add command uses the same code to create media, same error happens there. I brought up the add command because it is very to easy to check. You just cd to any sonata project and run the command. The main issue is you can't add media using the referenced code. |
I need more time to investigate. So far my findings are that it is harder to reproduce on a unit test, but I can clearly reproduce on the functional test, running the command directly. Seems related to a missing step during the upload process because I can updateMetadata on a media and it works fine, with or without file extension. The process to fix this requires a test to ensure no regressions after, so thats why is not as simple as opening a project and running the command you provided. |
First we want to verify if a bug really exist? or a user error. To answer that yes/no question you can run the command to verify, that was my intention. From my POV it looked like you were trying to reproduce it using complex testing technology while running a simple command would do. I mean the issue is still marked
Ah, I understand. |
Until right now I couldn't confirm it exists thats why it does have the label. |
ea92647
to
c45984c
Compare
036103e
to
9c30b7c
Compare
The focus of the PR has changed a bit after finding why it doesn't work without extensions, more here: #2208 |
9c30b7c
to
ac58654
Compare
…atch with the uploaded image
ac58654
to
ff6ffbc
Compare
Thank you @jordisala1991! |
Subject
I am targeting this branch, because this is a bugfix.
Closes #2208 .
Changelog