Modules

ballerinax/azure_storage_service.files Ballerina library

0.1.2
Ballerina Azure Storage File Service Connector

Build Status GitHub Last Commit License

Connects to Azure Storage File Service using Ballerina.

Introduction

What is Azure Storage Service

Azure Storage Service is a highly available, scalable, secure, durable and redundant cloud storage solution form Microsoft. There are four types of storage which are Blob Storage, File Storage, Queue Storage and Table Storage.

Azure Storage - Files Service

Azure File Storage Serviceis a shared network file storage service that provides administrators a way to access native SMB file shares in the cloud Files stored in Azure File service shares are also accessible via REST APIs.

Connector Overview

Azure Storage File Service Connector is used to connect to Azure Storage File Service via Ballerina language easily. It is capable to connect to Azure Storage File Service and to execute operations like getFileList, getDirectoryList, createDirectory, directUpload and getFile etc using the FileClient. It is also capable of executing management operations such as createShare and deleteShare etc using the ManagementClient.

image

This connector will invoke the REST APIs exposed via the Azure Storage File Service. https://docs.microsoft.com/en-us/rest/api/storageservices/file-service-rest-api

For the version 0.1.0 of this connector, version 2019-12-12 of Azure File Storage Service REST API is used.

Prerequisites

Supported Versions

Version
BallerinaSwan Lake Alpha 5
Azure Storage Service2019-12-12
Quickstart(s)

Simple operations in Azure File Service File Client.

These are the simplest scenarios in Azure File Service File Client. You must have the following prerequisites in order to obtain these configurations.

Step1: Import the Azure Storage Blobs Ballerina Library

First, import the ballerinax/azure_storage_service.files module into the Ballerina project.

Copy
import ballerinax/azure_storage_service.files as azure_files;

Step2: Create Azure File Service Configuration

Create the connection configuration using the Shared Access Signature or Access Key, base URL and account name.

If you are using Shared Access Signature, use the follwing format.

Copy
azure_files:AzureFileServiceConfiguration fileServiceConfig = {
    accessKeyOrSAS: os:getEnv("ACCESS_KEY_OR_SAS"),
    accountName: os:getEnv("ACCOUNT_NAME"),
    authorizationMethod: "SAS"
};

If you are using one of the Access Key, use the follwing format.

Copy
azure_files:AzureFileServiceConfiguration fileServiceConfig = {
    accessKeyOrSAS: os:getEnv("ACCESS_KEY_OR_SAS"),
    accountName: os:getEnv("ACCOUNT_NAME"),
    authorizationMethod: "accessKey"
};

Step3: Initialize Azure Storage File Client

Create the FileClient using the configuration you have created as shown above.

Copy
azure_files:FileClient fileClient = check new (fileServiceConfig);

Step4: Try the common operations in Azure Storage File Client

  1. Get list of directories in a file share
Copy
var result = fileClient->getDirectoryList(fileShareName = "demoshare");
if (result is azure_files:DirectoryList) {
    log:printInfo(result.toString());
} else {
    log:printInfo(result.message());
}
  1. Get list of files in a file share
Copy
var result = fileClient->getFileList(fileShareName = "demoshare");
if (result is azure_files:FileList) {
    log:printInfo(result.toString());
} else {
    log:printInfo(result.message());
}
  1. Create a directory
Copy
var result = fileClient->createDirectory(fileShareName = "demoshare", newDirectoryName = "demoDirectory");
if (result is error) {
    log:printInfo(result.message());
}
  1. Upload a file to a fileshare.
Copy
var uploadResponse = fileClient->directUpload(fileShareName = "demoshare", 
localFilePath = "resources/uploads/test.txt", azureFileName = "testfile.txt");
if (uploadResponse is error) {
    log:printError(uploadResponse.message()); 
}
  1. Download a file from a fileshare.
Copy
var downloadResponse = fileClient->getFile(fileShareName = "demoshare", fileName = "testfile.txt",
localFilePath = "resources/downloads/downloadedFile.txt");
if (downloadResponse is error) {
   log:printError(DownloadResponse.message());
}

Please check the sample directory for more examples.

Import

import ballerinax/azure_storage_service.files;Copy

Metadata

Released date: almost 3 years ago

Version: 0.1.2

License: Apache-2.0


Compatibility

Platform: java11

Ballerina version: slalpha5


Pull count

Total: 9986

Current verison: 375


Weekly downloads


Source repository


Keywords

azure

storage

blob

file


Contributors

Other versions

See more...