Cloudinary Blog

File Upload With Angular to Cloudinary

Angular File Upload to Cloudinary in Two Simple Steps

Angular is a Typescript-based open source framework for building mobile and web applications. It’s very different from AngularJS because it’s a complete rewrite from ground up. Angular is currently at version 9 and its usage amongst developers keeps increasing by the day.

Performing an Angular file upload to Cloudinary involves a two-part process:

  • The client side (the user interface) obtains the files to be uploaded through a form control or component.
  • The server side of the app receives, processes, transforms and stores the files in the cloud.

To make all that happen, set up an HTML template and build an Angular file upload component. The sections below walk you through the procedures in detail.

Angular File Upload

Enabling Angular file uploads to Cloudinary takes two steps.

Step 1: Set Up an HTML Template

First, place a file upload component in your app for your users by doing either of the following:

  • Specify, in HTML, the HTML5 file’s input type by adding the code below to the app.component.html file:

    Copy to clipboard
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file">
    <label>Choose file</label>
  • Install the Angular file upload component ng2-file-upload with this NPM command:

    Copy to clipboard
    npm install ng2-file-upload --save
    • Afterwards, attach the Angular file upload component to your HTML markup by adding the related parameters to the app.component.html file:

      • For multiple file uploads
      Copy to clipboard
      `<input type="file" ng2FileSelect [uploader]="uploader" multiple  />`
      • For single file uploads
      Copy to clipboard
      `<input type="file" ng2FileSelect [uploader]="uploader" />`
      `<button [disabled]="loading" (click)="upload()" class="btn">Upload</button>`

Step 2: Create an Angular File Upload Component

First, install the Angular File Upload Cloudinary library that works for Angular 5, 6, and 7 with this NPM command:

Copy to clipboard
npm install @cloudinary/angular-5.x --save

Now create an angular file upload component by adding the code below to the src/app/app.component.ts file:

Copy to clipboard
import { Component, OnInit, Input } from '@angular/core';
import { FileUploader, FileUploaderOptions, ParsedResponseHeaders } from 'ng2-file-upload';
import { Cloudinary } from '@cloudinary/angular-5.x';

  selector: 'app-list',
  templateUrl: 'app.component.html'
export class ImageUploadComponent implements OnInit {

  responses: Array<any>;

  private hasBaseDropZoneOver: boolean = false;
  private uploader: FileUploader;
  private title: string;

    private cloudinary: Cloudinary,
    private zone: NgZone,
    private http: HttpClient
  ) {
    this.responses = [];
    this.title = '';

  ngOnInit(): void {
    // Create the file uploader, wire it to upload to your account
    const uploaderOptions: FileUploaderOptions = {
      url: `${this.cloudinary.config().cloud_name}/upload`,
      // Upload files automatically upon addition to upload queue
      autoUpload: true,
      // Use xhrTransport in favor of iframeTransport
      isHTML5: true,
      // Calculate progress independently for each uploaded file
      removeAfterUpload: true,
      // XHR request headers
      headers: [
          name: 'X-Requested-With',
          value: 'XMLHttpRequest'

    this.uploader = new FileUploader(uploaderOptions);

    this.uploader.onBuildItemForm = (fileItem: any, form: FormData): any => {
      // Add Cloudinary unsigned upload preset to the upload form
      form.append('upload_preset', this.cloudinary.config().upload_preset);

      // Add file to upload
      form.append('file', fileItem);

      // Use default "withCredentials" value for CORS requests
      fileItem.withCredentials = false;
      return { fileItem, form };

  fileOverBase(e: any): void {
    this.hasBaseDropZoneOver = e;

Replace the variable cloud_ name in the code above with your account’s cloud name as displayed in your Cloudinary Dashboard.

The ImageUpload component in the code processes the uploaded files through the ng2-file-upload component, subsequently uploading them to Cloudinary.

Remarkably, such a setup eliminates the tedious chore of developing a back-end API to receive files from the front-end and to validate and process them before storing them in Cloudinary. As soon as a user has uploaded a file, Cloudinary seamlessly handles the remaining tasks that culminate in the file being stored in the Media Library.

For the complete code of the entire process, see this comprehensive GitHub repository.

AngularJS File Uploads

For app developers who are on AngularJS, follow the steps below to facilitate AngularJS file uploads.

First, install the Cloudinary AngularJS SDK and the ng-file-upload library with this NPM command:

Copy to clipboard
bower install ng-file-upload cloudinary_ng --save

Next, define CloudinaryProvider in your app’s configuration file with this code:

Copy to clipboard
yourApp.config(['cloudinaryProvider', function (cloudinaryProvider) {
      .set("cloud_name", "good")
      .set("secure", true)
      .set("upload_preset", "my_preset");

Replace the variable cloud_ name with your account’s cloud name as displayed in your Cloudinary Dashboard.

Finally, attach an uploadFiles function in your app to the controller $scope with, for example, this code:

Copy to clipboard
$scope.uploadFiles = function(files){
  $scope.files = files;
  angular.forEach(files, function(file){
    if (file && !file.$error) {
      file.upload = $upload.upload({
        url: "" + cloudinary.config().cloud_name + "/upload",
        data: {
          upload_preset: cloudinary.config().upload_preset,
          context: 'image=' + $scope.title,
          file: file
      }).progress(function (e) {
        file.progress = Math.round((e.loaded * 100.0) /;
        file.status = "Uploading... " + file.progress + "%";
      }).success(function (data, status, headers, config) {
        $rootScope.list = $rootScope.list || [];
        data.context = {custom: {image: $scope.title}};
        file.result = data;
      }).error(function (data, status, headers, config) {
        file.result = data;

The $upload.upload function uploads all the files straight to Cloudinary.

Manipulate and Deliver Uploaded Angular Or AngularJS Files

Cloudinary’s Angular SDK contains several out-of-the-box components that enable you to manipulate, optimize, and deliver images in the best format. Add those components to your Angular app.

Afterwards, specify the attributes and values that you desire for the parameters for the <cl-image> component, for example:

Copy to clipboard
<cl-image public-id="dog" angle="20" format="jpg">
    <cl-transformation height="150" width="150" crop="fill" effect="sepia"></cl-transformation>
    <cl-transformation overlay="text:arial_20:Angular" color="#EECCAA" gravity="south" y="20"></cl-transformation>

In the above code, the value of public-id (dog) is the name of the image stored in Cloudinary.

To manipulate and transform images and files as you desire, simply embed the <cl-transformation> component within <cl-image>. For details of the many options available, see the related Cloudinary documentation. You’ll be amazed at the wealth of choices at your fingertips and the marvelous effects the manipulation and transformation tasks produce. Do give it a whirl!

Recent Blog Posts

Automatic Video Creation for Social Media at Scale

With video becoming increasingly popular, especially across social media, it’s as important as ever to ensure that your videos aren’t one of the hundreds that people just scroll on past. There’ve been a few successful techniques over the last couple of years to help with that, such as—

Read more
Uploading, Managing and Delivering PDFs With Cloudinary

The Portable Document Format (PDF) is a popular format developed by Adobe for delivering formatted text and images. A PDF file includes a complete description of all layout elements, including text, fonts, images and layers, ensuring that the file will look identical when opened on any device. The PDF format also has the big advantage of compressing high-quality files to a relatively small file size.

Read more
Share Your DAM Assets! New Visual Collections + Media Portal

If you've been working at home with young kids around during these “corona days”, you might have intuitively expected the last word of the title above to be "Toys" or "Candy"   😜. However, if you're a member of a creative team for a web site or software application, then you know how essential it is to have simple ways to share and collaborate on pre-production media assets.

Read more