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

Add support for files upload #875

Closed
wants to merge 1 commit into from
Closed

Conversation

ker0x
Copy link
Contributor

@ker0x ker0x commented Oct 14, 2018

This is a first approach to handle file upload into the app as requested in #743.

What i did:

  • Create two Annotations Uploadable and UploadableField to mark an Entity has uploadable. This is very similar to what VichUploaderBundle do, but with less more feature.
  • Create a Doctrine subscriber, to handle file upload on entity
  • Add an interface and a trait to mark an entity as Timestampable since i need to modify at least on field to take care of the file upload.
  • Update templates

What i didn't do:

  • Use a third party bundle. IMO, as this is a demo application, we should first show people how to do things with the framework, before relaying on bundle.
  • Add tests. Currently i don't know how to test file upload with PHPUnit, some help will be appreciate 👍
  • Add the modified database because i don't know if it's fine! It could be great if Added migrations #779 can be merged. I could then add a migration file.

HOWEVER, while testing this, I encounter 2 errors:

  • The first one occurs when I submit a form without adding a file. I systematically get the following error:
1/1) ErrorCall to a member function getClientOriginalName() on null
--
in RequestDataCollector.php line 64
at RequestDataCollector->collect(object(Request), object(RedirectResponse), null)in Profiler.php line 167
at Profiler->collect(object(Request), object(RedirectResponse), null)in ProfilerListener.php line 91
at ProfilerListener->onKernelResponse(object(FilterResponseEvent), 'kernel.response', object(TraceableEventDispatcher))in WrappedListener.php line 104
at WrappedListener->__invoke(object(FilterResponseEvent), 'kernel.response', object(EventDispatcher))in EventDispatcher.php line 212
at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener),object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.response', object(FilterResponseEvent))in EventDispatcher.php line 44
at EventDispatcher->dispatch('kernel.response', object(FilterResponseEvent))in TraceableEventDispatcher.php line 141
at TraceableEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent))in HttpKernel.php line 189
at HttpKernel->filterResponse(object(RedirectResponse), object(Request), 1)in HttpKernel.php line 171
at HttpKernel->handleRaw(object(Request), 1)in HttpKernel.php line 67
at HttpKernel->handle(object(Request), 1, true)in Kernel.php line 188
at Kernel->handle(object(Request))in index.php line 37
  • Second one happen when i submit the form with a file:
(1/2) FileNotFoundExceptionThe file "/tmp/phpoXdkSq" does not exist
--
in MimeTypeGuesser.php line 116
at MimeTypeGuesser->guess('/tmp/phpoXdkSq')in File.php line 79
at File->getMimeType()in RequestDataCollector.php line 65
at RequestDataCollector->collect(object(Request), object(RedirectResponse), null)in Profiler.php line 167
at Profiler->collect(object(Request), object(RedirectResponse), null)in ProfilerListener.php line 91
at ProfilerListener->onKernelResponse(object(FilterResponseEvent), 'kernel.response', object(TraceableEventDispatcher))in WrappedListener.php line 104
at WrappedListener->__invoke(object(FilterResponseEvent), 'kernel.response', object(EventDispatcher))in EventDispatcher.php line 212
at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener),object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.response', object(FilterResponseEvent))in EventDispatcher.php line 44
at EventDispatcher->dispatch('kernel.response', object(FilterResponseEvent))in TraceableEventDispatcher.php line 141
at TraceableEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent))in HttpKernel.php line 189
at HttpKernel->filterResponse(object(RedirectResponse), object(Request), 1)in HttpKernel.php line 171
at HttpKernel->handleRaw(object(Request), 1)in HttpKernel.php line 67
at HttpKernel->handle(object(Request), 1, true)in Kernel.php line 188
at Kernel->handle(object(Request))in index.php line 37

The file is correctly uploaded and the field in the database is filled in 😞

I have the same upload implementation in another project, on Symfony 4.1.6 and everything works fine. If anyone has any idea what's wrong, I'm interested. I tested it on the internal PHP server and on a VM with Homestead, I have the same errors.

@ker0x ker0x force-pushed the feature/issue-743 branch 3 times, most recently from 2f9bc3c to 1306040 Compare December 5, 2018 08:33
@ker0x ker0x force-pushed the feature/issue-743 branch 2 times, most recently from 3065dfe to f821357 Compare December 17, 2018 13:26
@ker0x ker0x force-pushed the feature/issue-743 branch from f821357 to f6f69c3 Compare October 7, 2019 14:17
@nicolas-grekas nicolas-grekas changed the base branch from master to main November 19, 2020 12:37
@ker0x ker0x closed this Nov 4, 2021
@javiereguiluz
Copy link
Member

Romain, I'm sorry because of the lack of feedback to this contribution of yours. I want to apologize because I handled this wrongly. I should have replied earlier and say that this was probably a bit too much for the demo application. In any case, thanks for your contribution 🙏

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

Successfully merging this pull request may close these issues.

2 participants