Cloudinary Angular Photo Album Sample
This sample project shows:
- How to use the Cloudinary Angular directives.
- How to upload files to Cloudinary in an unsigned manner, using an upload preset. The upload control is based on the open source file uploader ng2-file-upload
- How to use the dynamic list resource in order to maintain a short list of resources aggregated by tags.
- How to delete an image uploaded from the browser with an unsigned upload. You can find additional details in this knowledge base article. Don't forget to set the
Return delete tokensetting of your unsigned upload preset to
There are 2 settings you need to change for this demo to work. Copy or rename
app/js/config.ts and edit the following:
- cloud_name - Should be change to the cloud name you received when you registered for a Cloudinary account.
- upload_preset - You should first "Enable unsigned uploads" in the "Upload Settings" of your Cloudinary console and assign the resulting preset name to that field. Note, you may want to tweak and modify the upload preset's parameters.
- Additionally, in your Cloudinary console in the "Security Settings" section you should uncheck the "list" item.
npm install to install the required dependencies for this module.
npm start to start the server and automatically open a browser and navigate to the application's url.
The application is deployed at http://localhost:8002/
This sample is using Webpack for bundling and serving the application.
index.html bootstraps the application by loading the
bundle.js script generated by Webpack.
The sample creates a new NgModule, and depends on CloudinaryModule which is imported from the SDK module.
Sample main components
The application routes are defined in app/js/app.routing.ts
The application has 2 routes:
- /photos - Presents a list of images tagged by
- /photos/new - Presents an upload control that allows uploading multiple files by a file input or drag-and-grop. Uploads have a dynamic progress bar. In addition it displays the details of successful uploads.
The default route is set to
photo-album.service.ts retrieves the list of images from Cloudinary based on the
myphotoalbum tag name.
- photo-list.component.ts sets up the list of images displayed via one-way binding by photo-list.component.html
- photo-list.component.html displays the bound images and displays basic transformations for each image
- photo-upload-jquery.component.ts initializes the upload widget and sets up listeners on the progress events.
- photo-upload-jquery.component.html displays the upload control and lists the properties of the uploaded images once upload completes successfully.
- This implementation is based on an Angular file uploader.
- Changes to the title field are propagated to the
formDatabeing sent in the upload request. This is meant to illustrate the possibility of attaching extra meta-data to each upload image.
- The upload control uses the
upload_presetwe configured in Configuration step. This uses the settings defined on Cloudinary side to process the uploaded file.
In order to add images to our photo album that would later be retrievable from the Cloudinary service we must select a tag which will serve as our source for the list. In this case
While this tag can be set in the upload preset and remain hidden from the client side, in this sample we included it in the request itself to make this sample work without further configuration steps.
Cloudinary supports a JSON list resource. This list represents all resources marked with a specific tag during upload (or later through other APIs). Whenever a new resource is uploaded with a tag, or an existing resource already tagged is deleted then the list is recalculated. This enables you to group a list of resources which can be retrieved by a single query. The size of the list is currently limited to 100 entires. Learn more