I am developing an app which needs to store images in Azure using Swift.
Is there any example that will be helpful ? If not can you give me a suggestion ?
Here is a simple example.
1- Start here: https://azure.microsoft.com/en-us/documentation/articles/storage-ios-how-to-use-blob-storage/
2- Get the SDK
3- Here is the code:
let account = AZSCloudStorageAccount(fromConnectionString:AZURE_STORAGE_CONNECTION_STRING) //I stored the property in my header file
let blobClient: AZSCloudBlobClient = account.getBlobClient()
let blobContainer: AZSCloudBlobContainer = blobClient.containerReferenceFromName("<yourContainerName>")
blobContainer.createContainerIfNotExistsWithAccessType(AZSContainerPublicAccessType.Container, requestOptions: nil, operationContext: nil) { (NSError, Bool) -> Void in
if ((NSError) != nil){
NSLog("Error in creating container.")
}
else {
let blob: AZSCloudBlockBlob = blobContainer.blockBlobReferenceFromName(<nameOfYourImage> as String) //If you want a random name, I used let imageName = CFUUIDCreateString(nil, CFUUIDCreate(nil))
let imageData = UIImagePNGRepresentation(<yourImageData>)
blob.uploadFromData(imageData!, completionHandler: {(NSError) -> Void in
NSLog("Ok, uploaded !")
})
}
}
Enjoy :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With