Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class AzureBlobStorage

  1. Object
  2. AzureBlobStorage

ImplementsObjectStorage

Azure Blob Storage, through its REST API, with no Azure library. A bucket here is a container and an object a block blob.

Two ways to authenticate:

  • An account key (Shared Key), from the key itself or a connection string. Presigned URLs are service SAS tokens computed here.
  • A managed identity (Microsoft Entra ID), on an Azure VM, App Service, Container Apps or Functions, with no secret on the machine. The identity needs a data-plane role such as “Storage Blob Data Contributor”. Presigned URLs are then user-delegation SAS tokens, which costs one call to fetch a delegation key a day.

forConnectionString with UseDevelopmentStorage=true talks to a local Azurite.

Nested types

class AzureBlobStorage.FactoryOpens azblob:// URLs for ObjectStorages: azblob://<account>.

Methods

public static AzureBlobStorage forAccountKey(String account, String key)The account account, authenticated with its base64 access key.
public static AzureBlobStorage forManagedIdentity(String account, String clientId)The account account, authenticated as the machine’s managed identity.
public static AzureBlobStorage forConnectionString(String connectionString) throws IOExceptionThe account a connection string from the Azure portal names, or Azurite for UseDevelopmentStorage=true.
public AzureBlobStorage withEndpoint(String endpoint)The same account and credentials at another endpoint: a sovereign cloud (https://<account>.blob.core.chinacloudapi.cn), a private endpoint, or an emulator, whose URL then includes the account path.
public String getName()The provider’s short name: s3 (Amazon S3 and every S3-compatible endpoint, R2 included), gcs, azure or memory.
public void createBucket(String bucket) throws IOExceptionCreates a bucket, and says nothing when this account already owns it.
public String putObject(String bucket, String key, byte[] content, String contentType) throws IOExceptionUploads an object, replacing one of the same key.
public byte[] getObject(String bucket, String key) throws IOExceptionDownloads an object.
public ObjectInfo headObject(String bucket, String key) throws IOExceptionThe object’s metadata, or null when it does not exist.
public void deleteObject(String bucket, String key) throws IOExceptionDeletes an object.
public List<String> listObjects(String bucket, String prefix, int max) throws IOExceptionUp to max keys under prefix (null or empty for all), following the provider’s pagination until the listing ends or max is reached.
public String presignGet(String bucket, String key, int seconds) throws IOExceptionA URL that downloads the object with no credentials, for seconds.
public String presignPut(String bucket, String key, int seconds) throws IOExceptionThe upload counterpart: a URL a client can PUT the bytes to, for seconds.

Inherited methods

Method details

forAccountKey

public static AzureBlobStorage forAccountKey(String account, String key)
The account account, authenticated with its base64 access key.

forManagedIdentity

public static AzureBlobStorage forManagedIdentity(String account, String clientId)
The account account, authenticated as the machine’s managed identity. clientId picks a user-assigned identity; null takes the system one.

forConnectionString

public static AzureBlobStorage forConnectionString(String connectionString) throws IOException
The account a connection string from the Azure portal names, or Azurite for UseDevelopmentStorage=true. It must carry an AccountKey; a connection string holding only a SAS is not supported.

Throws

IOException
when the string names no account or key

withEndpoint

public AzureBlobStorage withEndpoint(String endpoint)
The same account and credentials at another endpoint: a sovereign cloud (https://<account>.blob.core.chinacloudapi.cn), a private endpoint, or an emulator, whose URL then includes the account path.

getName

public String getName()
The provider’s short name: s3 (Amazon S3 and every S3-compatible endpoint, R2 included), gcs, azure or memory.

createBucket

public void createBucket(String bucket) throws IOException

Creates a bucket, and says nothing when this account already owns it.

Usually infrastructure’s job, but a first run against an emulator or a test fixture needs it.

putObject

public String putObject(String bucket, String key, byte[] content, String contentType) throws IOException

Uploads an object, replacing one of the same key. Returns its ETag, the provider’s receipt for exactly these bytes.

contentType may be null, which stores application/octet-stream.

getObject

public byte[] getObject(String bucket, String key) throws IOException
Downloads an object. Throws when it is missing, rather than returning null.

headObject

public ObjectInfo headObject(String bucket, String key) throws IOException
The object’s metadata, or null when it does not exist.

deleteObject

public void deleteObject(String bucket, String key) throws IOException
Deletes an object. Deleting one that is not there is not an error.

listObjects

public List<String> listObjects(String bucket, String prefix, int max) throws IOException
Up to max keys under prefix (null or empty for all), following the provider’s pagination until the listing ends or max is reached. Zero answers an empty list; a negative max is refused.

presignGet

public String presignGet(String bucket, String key, int seconds) throws IOException

A URL that downloads the object with no credentials, for seconds.

Computed, not requested, wherever the provider allows it: the URL can be handed straight to a client. A lifetime the provider refuses – zero or less, or past seven days on S3, R2 and GCS – throws an IOException on every provider, so moving between them does not change how it fails.

presignPut

public String presignPut(String bucket, String key, int seconds) throws IOException

The upload counterpart: a URL a client can PUT the bytes to, for seconds.

Azure needs one header on that PUT that the others do not: x-ms-blob-type: BlockBlob. A client that serves more than one provider can send it everywhere; S3 and GCS ignore it.