How to Synchronize Amazon S3 Storage Files with Essential JS 2 File Manager
Tags: webdev, angular, javascript, aws
Published: 2019-10-24 07:37:08

---
title: How to Synchronize Amazon S3 Storage Files with Essential JS 2 File Manager
published: true
date: 2019-10-23 11:00:10 UTC
tags: webdev, angular, javascript, aws
canonical_url: https://www.syncfusion.com/blogs/post/synchronize-amazon-s3-with-js-file-manager.aspx
cover_image: https://thepracticaldev.s3.amazonaws.com/i/5xalgx2ijhp8o1vwaoid.jpg
---

Having an important file on a machine and limiting its sharing scope within an organization is no longer adequate for many corporate offices. As organizations expand around the world, people nowadays prefer to share and access such documents globally from anywhere. [Amazon S3](https://aws.amazon.com/s3/) (Simple Storage Service) provides a preferable public cloud storage resource for storing any data files in the cloud, like videos, images, documents, and more.

In this blog, I’ll walk you through how to synchronize the files and folders present in an Amazon S3 bucket with our Essential JS 2 File Manager component. The Essential JS 2 [File Manager](https://www.syncfusion.com/javascript-ui-controls/js-file-manager) is a UI component built by Syncfusion that allows you to view and interact with a hierarchical collection of files and folders. Using this component, you can easily manage the file system and perform most common file and folder operations like read, write, delete, create, rename, upload, edit, select, and sort. It is also available on all major web platforms, including [Angular](https://www.syncfusion.com/angular-ui-components/angular-file-manager), [React](https://www.syncfusion.com/react-ui-components/react-file-manager), [Vue](https://www.syncfusion.com/vue-ui-components/vue-file-manager), [JavaScript](https://www.syncfusion.com/aspnet-core-ui-controls/file-manager), [ASP.NET MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls/file-manager), [ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls/file-manager), and [Blazor](https://www.syncfusion.com/blazor-components/blazor-file-manager).

Moreover, you can easily cross-verify whether the files and folders displayed in the File Manager component are identical to those present in the Amazon S3 storage bucket. Let’s start with what Amazon S3 is first and then I’ll proceed with the steps to synchronize it with the Essential JS 2 File Manager.

## What is Amazon S3?

[Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html) (Simple Storage Service) is a simple web storage services interface that you can use to store and retrieve any amount of data at any time from anywhere on the web. It provides highly scalable, reliable, fast, and inexpensive data storage infrastructure.

## Creation of an Amazon S3 Bucket

**Step 1:** To create a new S3 bucket, sign in to the AWS (Amazon Web Services) management console and open the [**Amazon S3 console**](https://console.aws.amazon.com/s3/). Now, select the S3 service from the storage options.

![AWS S3 Console Storage Options](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/AWS-S3-Console-Storage-Options.png)<figcaption>AWS S3 Console Storage Options</figcaption>

**Step 2:** Click **Create bucket** to start creating an AWS S3 bucket.

![Create AWS S3 Bucket](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Create-AWS-S3-Bucket.png)<figcaption>Create AWS S3 Bucket</figcaption>

**Step 3:** Provide a unique bucket name and select the region where the bucket should exist. After providing these details, click the **Create** button. You have now successfully created an S3 bucket using Amazon Web Services.

**Step 4:** Now, **upload files to the bucket.** To upload a file, first select your bucket and then click the **Upload** button.

![Uploading Files to an S3 Bucket](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Uploading-Files-to-an-S3-Bucket.png)<figcaption>Uploading Files to an S3 Bucket</figcaption>

**Step 5:** Set your bucket as **public** by right-clicking on the created bucket and then choosing the **Make public** option.

![Making a Bucket Public](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Making-a-Bucket-Public.png)<figcaption>Making a Bucket Public</figcaption>

Now your new bucket is ready to use, so let’s see how to transfer the data from Amazon S3 storage to the Essential JS 2 File Manager component. In the next step we will create an intermediate ASP.NET Core project which acts as a service provider that will connect with the File Manager component.

## Creating an Amazon S3 File Provider Project

The ASP.NET Core **Amazon S3 file provider** project acts as a gateway to synchronize the content between the File Manager component and Amazon S3 bucket storage. The files will flow as follows:

Amazon S3 Storage > Amazon File Provider > Essential JS 2 File Manager component

## GitHub Example

You can download the Amazon S3 file provider source project from the following GitHub location:

[https://github.com/SyncfusionExamples/ej2-amazon-s3-aspcore-file-provider](https://github.com/SyncfusionExamples/ej2-amazon-s3-aspcore-file-provider).

An important step in this Amazon S3 file provider ASP.NETCore project is to ensure that you have registered your Amazon S3 client account details like awsAccessKeyId, awsSecretAccessKey, bucketRegion, and bucketName using the [RegisterAmazonS3 ](https://github.com/SyncfusionExamples/ej2-amazon-s3-aspcore-file-provider/blob/master/Controllers/AmazonS3ProviderController.cs#L28)method to perform the file operations.

```js
void RegisterAmazonS3(string bucketName, string awsAccessKeyId, string awsSecretAccessKey, string bucketRegion);
```

## Run the application

1. Open a command prompt, clone this ready-to-use [project](https://github.com/SyncfusionExamples/ej2-amazon-s3-aspcore-file-provider) from GitHub, and then navigate to the path where it has been placed in your system by running the following commands in order.
```
git clone https://github.com/ej2-amazon-s3-aspcore-file-provider cd ej2-amazon-s3-aspcore-file-provider
```
2. Now, restore the NuGet packages by running the following command from the root folder.
```
dotnet restore
```
3. Build the application using the following command.
```
dotnet build
```
4. After a successful compilation, run the following command to run this file provider application.
```
dotnet run
```

Now, the project will be hosted at [http://localhost](http://localhost). To ensure that Amazon-s3-service works, type the following URL in your browser.

[http://localhost:<port-number>/api/test](http://localhost:<port-number>/api/test)

**Note:** Make sure to map the proper in the above URL.

## Configuring File Provider Service in Essential JS 2 File Manager

Now the service project is ready to use, so next I’ll create a basic JavaScript File Manager example by referring to the [getting started documentation](https://ej2.syncfusion.com/documentation/file-manager/getting-started/). You can also get a runnable and pre-configured example from <u>this </u>[GitHub repository](https://github.com/SyncfusionExamples/How-to-sync-the-Amazon-S3-storage-files-with-the-EJ2-file-manager-component).

To perform the basic file actions such as read, delete, copy, move, rename, and search, and to retrieve the details of files from the Amazon S3 service, start mapping the following service URLs to the **ajaxSettings** property of File Manager.

**Note:** The hostUrl will be the locally hosted port number of the S3 file provider project that was created in the previous step.

```js
var hostUrl = http://localhost:<Port Number>/;
  ajaxSettings: {
        url: hostUrl + 'api/AmazonS3Provider/AmazonS3FileOperations'
  }
```

## Perform download operation

To enable and perform download operations on the files, initialize the **downloadUrl** property within the **ajaxSettings** of the File Manager component.

```js
var hostUrl = http://localhost:<Port Number>/;
ajaxSettings: {
      url: hostUrl + ‘api/AmazonS3Provider/AmazonS3FileOperations’,
      downloadUrl: hostUrl + ‘api/AmazonS3Provider/AmazonS3Download’
}
```

## Perform upload operation

To perform the upload operation in the File Manager, initialize the **uploadUrl** property within the **ajaxSettings** of the File Manager component as shown in the following sample.

```js
var hostUrl = http://localhost:<Port Number>/;
ajaxSettings: {
      url: hostUrl + 'api/AmazonS3Provider/AmazonS3FileOperations',
      uploadUrl: hostUrl + 'api/AmazonS3Provider/AmazonS3Upload'
}
```

![File uploaded to File Manager and synchronized with S3 bucket.](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Perform-upload-operation.png)<figcaption>File uploaded to File Manager and synchronized with S3 bucket.</figcaption>

## Image preview settings

To enable the image preview settings in the File Manager component, initialize the **getImageUrl** property within the **ajaxSettings** property as shown in the following code.

```js
var hostUrl = http://localhost:<Port Number>/;
ajaxSettings: {
      url: hostUrl + 'api/AmazonS3Provider/AmazonS3FileOperations',
       getImageUrl: hostUrl + 'api/AmazonS3Provider/AmazonS3GetImage'
}
```

![Image preview Essential JS 2 File Manager](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Image-preview-Essential-JS-2-File-Manager.png)<figcaption>Image preview in Essential JS 2 File Manager</figcaption>

Now, the Essential JS 2 File Manager will be rendered with the same files and folders as in the Amazon S3 bucket object as shown in the following screenshot.

![File Manager Component Synchronized with an S3 Bucket](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/File-Manager-Component-Synchronized-with-an-S3-Bucket.png)<figcaption>File Manager Component Synchronized with an S3 Bucket</figcaption>

## Conclusion

To summarize, the ability to synchronize and share files and folders between an Amazon S3 bucket and the Syncfusion File Manager component allows you to have global access to local files and folders. If we make any changes to the files and folders present in the Amazon S3 cloud bucket, those changes will be reflected immediately in the File Manager component and vice versa. In just a few steps, you can create and deploy an application that uses the [Essential JS 2 File Manager](https://www.syncfusion.com/javascript-ui-controls/js-file-manager) and connects to Amazon S3 bucket storage in a simpler way.

Try this out with our [2019 Volume 3](https://www.syncfusion.com/forums/148058/essential-studio-2019-volume-3-release-v17-3-0-14-is-available-for-download) release and share your feedback as comments on this blog. If you need support for specific features in this component or have any questions, contact us through our [support forum](https://www.syncfusion.com/forums), [Direct Trac](https://www.syncfusion.com/support/directtrac/), or [feedback portal](https://www.syncfusion.com/feedback/xamarin-forms). We are waiting to hear what you think about this feature!

The post [How to Synchronize Amazon S3 Storage Files with Essential JS 2 File Manager](https://www.syncfusion.com/blogs/post/synchronize-amazon-s3-with-js-file-manager.aspx) appeared first on [Syncfusion Blogs](https://www.syncfusion.com/blogs).