Jeff
Jeff

Reputation: 850

Azure Blob Storage Image URL? iOS

Im trying to retrieve the URL of a blob item in a container. Using Azure's instructions I have successfully uploaded an image and retrieved the image as data but this is not ideal in my situation.

In Azure Storage Explorer there is in fact a url for each blob item in a container but I simply can't figure out how to get it in code. Can someone point me in the right direction

Upvotes: 0

Views: 2756

Answers (2)

RJ raj
RJ raj

Reputation: 17

let containerURL = "https://yourstoragename.blob.core.windows.net/\(ContainerName)\(SASToken)"  
var container : AZSCloudBlobContainer       
var error: NSError?       
container = AZSCloudBlobContainer(url: NSURL(string: containerURL)! as URL, error: &error)       
if ((error) != nil) {
        print("Error in creating blob container object.  Error code = %ld, error domain = %@, error userInfo = %@", error!.code, error!.domain, error!.userInfo);
    }        
else {        
   let blob = container.blockBlobReference(fromName: "Image.png") 
    blob.downloadToFile(withPath: fromfile, append: true, completionHandler:{(NSError) -> Void in
                var blobUrl = blob.storageUri.primaryUri               
    })
}

Upvotes: 0

Joey Cai
Joey Cai

Reputation: 20067

In Azure Storage Explorer there is in fact a url for each blob item in a container but I simply can't figure out how to get it in code.

In fact, I am not very clear about what you want is listing blob url or getting the blob item. For both of them, you could use Azure Storage Client Library for iOS to achieve.

So, if you want to get the blob url in container, you could use a helper method to recursively call the list blobs method every time a continuation token is returned.

For a blob, the base URI includes the name of the account, the name of the container, and the name of the blob:

https://myaccount.blob.core.windows.net/mycontainer/myblob  

For example:

https://storagename.blob.core.windows.net/container/a/b/c.txt

If you would get the blob item in container, you could download a blob to a NSString object.

For more detailed description and code, you could read this article.

Upvotes: 2

Related Questions