Sub*_*ose 7 azure ios azure-mobile-services swift
我正在开发一个需要使用Swift在Azure中存储图像的应用程序.
有什么例子会有帮助吗?如果没有,你能给我一个建议吗?
这是一个简单的例子.
1-从这里开始:https://azure.microsoft.com/en-us/documentation/articles/storage-ios-how-to-use-blob-storage/
2-获取SDK
3-以下是代码:
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 !")
})
}
}
Run Code Online (Sandbox Code Playgroud)
请享用 :)
您必须使用他们的REST API ,但他们现在正在开发SDK 。
有几个在 iOS 上使用 REST API 的示例。粗略搜索会出现:Uploading to azure blob storage from SAS URL returns 404 status
Github 上还有这个示例 - https://github.com/Ajayi13/BlobExample-Swift
归档时间: |
|
查看次数: |
2997 次 |
最近记录: |