Home > Software engineering >  How to store image files in Azure Cosmos DB?
How to store image files in Azure Cosmos DB?

Time:09-12

I am trying to upload images to azure cosmos DB but can't find any documentation.

We are using the new version of cosmos DB library:

implementation 'com.azure:azure-cosmos:3.1.0'

I found AsyncDocumentClient from com.microsoft.azure.cosmosdb.rx package which has

public Observable<>> createAttachment(String documentLink, Attachment attachment, RequestOptions options)

public Observable<>> createAttachment(String documentLink, InputStream mediaStream, MediaOptions options, RequestOptions requestOptions)


but this library(java Async SDK v2) has been deprecated and replaced with the new SDK(Java Sdk v4). I cant find anything regarding managed attachments in the new SDK. What options do we have to upload the files now?

PS. I know we should use blob storage from azure, but we don't have it right now

CodePudding user response:

You really should move to blob storage, attachments are obsolete as stated in the docs:

Attachment is a legacy feature. Their support is scoped to offer continued functionality if you are already using this feature.

Instead of using attachments, we recommend you to use Azure Blob Storage as a purpose-built blob storage service to store blob data . You can continue to store metadata related to blobs, along with reference URI links, in Azure Cosmos DB as item properties. Storing this data in Azure Cosmos DB provides the ability to query metadata and links to blobs stored in Azure Blob Storage.

That is why you won't find it in newer SDKs. So either stick to an older library (not recommended) or move to the new approach.

  • Related