Uploading Movies
Finally, take the modal in the preceding section live.
Upload the Modal Trigger
To upload the modal trigger:
Add a button to the navigation bar for launching the upload modal on a click:
Every time you click that button, it flips a
showModal
boolean. Add the property to the data model:Add
UploadModal
to theApp
component as a child. Start with adding the element immediately below the containerdiv
:Note that you are passing down
showModal
to the component. You will learn about thehandle-upload
event later.Import
UploadModal
toApp
:
Watch showModal
showModal
You show the modal according to the value of the showModal
property in the UploadModal
component:
Click the Upload button for the modal:
Upload an Image or a Video
On a click of each of the Upload buttons on the modal, the startUpload
method is called but with different arguments. Create that method as follows:
startUpload
launches the upload widget, which enables you to upload images or videos. After the upload, depending on which button was clicked, set the value to reflect the banner or trailer model.
Besides cloud_name
, you must also create upload_preset
, unsigned, to enable uploads. To do so, fill in the fields on Cloudinary's Upload settings page under the upload prest section.
The upload widget uses another library for modularity. Add the following code below the scripts in the public/index.html
file:
Clicking the Upload button on the modal displays this widget:
Generate an Upload Event
The form contains an attached handleUpload
event, which ensures that on a click of the Submit button, the titles and IDs of the media content are displayed. handleUpload
checks if those values are available before generating an event to the parent component for an upload.
Add this code to the methods
object:
Upload to the Server
Recall that the element for UploadModal
reads like this:
The uploadToServer
method is the handler for the event generated in the child component. Create uploadToServer
in the methods
object:
uploadToServer
pushes to the server and updates the list with the new entry. It also hides the modal.
The App
component script reads:
Last updated