DEV Community

Andriy Andruhovski for Aspose.PDF

Posted on • Updated on

3 simple steps to start using Aspose.Cloud Storage

Solving the problems of document processing, we often encounter the problem of getting source documents from different sources and from different providers. Aspose.Cloud Storage is a component of Aspose.Cloud platform, which releases a transparent interface for access to different sources. Now Aspose.Cloud Storage supports popular services from Amazon, Dropbox, Google, Microsoft. Let's see how we can use this component.

Step 1: Create an Aspose.Cloud account

  • We can create a free Aspose.Cloud account using the link "Create a new Account" on http://dashboard.aspose.cloud or sign in with GitHub or Google Account.

SignIn/SignUp Form

  • When registering, for each account an Aspose.Cloud Storage is created. We add another storage later, and now we are trying to access the current storage using C#. To do this we need to get an application credential.

Step 2: Get an Application credentials

Aspose.Cloud Application allows us to manage access to Cloud API. By default, each account has one application named "First App". Using the "My Apps" tab, we can see the list of all applications, change settings or get the credential.

My Apps

The application credentials (App SID/App Key) are placed directly on the "First App" tile, but if you want to change the settings of the "First App", just click on tile heading. for testing purposes, we have enough default settings, so we will proceed to the next step, writing the client application. In this example, we will use a "Console Application" template in Microsoft Visual Studio 2017.

Step 3: Create a Client application

To demonstrate the main concept of the cloud storage working, we will write an application that will synchronize certain local folder with a cloud folder with the same name. So, let's start.

  1. Create a console application (in VS2017 File->New->Project>Windows Classic Desktop->Console App);
  2. Install Aspose.Storage for Cloud SDK (in Package Manager Console: Install-Package Aspose.Storage-Cloud) Install Aspose.Storage for Cloud SDK

Step 3a: Setup an API client

To be able making API requests, we must initialize an API client. It's pretty straightforward: declare StorageApi object and initialize it with AppKey and AppSID.

Step 3b: Write own code using API client

This part of our example will show the usage of most frequent API requests:

  • Check if a file exists
  • Create a folder
  • Get a list of files
  • Create (upload) file to cloud storage

It is worth noting, that all StorageApi methods accept a request object and returns a response object. All response objects have common properties such us Code and Status and we can use there to check if API call was successful.

According to our problem, we need to synchronize certain local folder with a cloud folder with the same name. So first, we must ensure that the cloud folder exists, otherwise create one. Storage API provides GetIsExist and PutCreateFolder.
Thus, checking if the cloud folder would look like this:

Next step, we prepare a file list for upload. What will we do? It's easy: we need to get a list of all files from the local folder and a list of files in the cloud. The difference of these lists give us a list of files need to upload.

Finally, we will call PutCreateDocument the loop through the resultant list.

Conclusion

  • Q: Is it one-way synchronizer?
  • A: Yes. It showed the main ways of usage Aspose.Cloud Storage, and you can improve it yourself.
  • Q: And what about other storages?
  • A: Learn more in the article "How to Configure 3rd Party Cloud Storages".
  • Q: What's next?
  • A: In the next posts, we will continue to deal with the Aspose.Cloud features.

Top comments (0)