Uploading An Image Using Crownpeak Access API

Posted by: Hitesh Padhiyar

The Crownpeak Access API is a library that enables web developers to create customer applications that can access many of the classes of the CMS API from outside the CMS environment. Using Accesss API, developers can create, import, and manage CMS Assets.

In this article we will cover how to upload an image [binary asset] from an asp.net application - into the CMS.

Prerequisites:

Understanding of C#, Crownpeak CMS, Crownpeak Access API

Lets Start:

The first step is to request the API KEY from Crpownpeak Support for your instance. To access the api, you will need this key along with your CMS login credentials.

Lets create a fresh asp.net project and add below mentioned dll as reference.

Add below namespace references wherever we need to use the api.

Add API related info into your web.config. These config keys hold credentials and instance information for connecting to Crownpeak thruogh Access API.

Create a helper class, where all the common code/functions related to login/connecting to Access Api will reside. Create a function to login via Access Api as below:

Above code block is used to login into the CMS and it returns a AccessSession object using with we will be able to perform the desired CMS actions.

For uploading the image into the CMS, we will need to specify the CMS path where it will be saved and a Model which holds the additional asset properties like the type of asset, workflows etc. To do this, add the below two keys in your web.config

Now create a method, that will take 2 parameters. One is file name and other is the InputStream. This method will connect and upload the file to the CMS.

Now, lets create an Asp.net page with the file upload control and a button as shown below

On click event of btnUpload, write the below code

Run the project. Output page would look like:

On click of the button, the selected image would be uploaded to Crownpeak CMS at the configured path.

Additional References:

  1. https://developer.crownpeak.com/Documentation/AccessAPI/index.html

  2. https://github.com/Crownpeak/Access-API-Examples

AccelerateBSi uses cookies to deliver superior functionality and to enhance your experience of our website. Continued use of this site indicates that you accept this policy.