将图像上载到Azure存储

时间:2017-05-15 14:28:54

标签: swift azure

当我上传图片以进行天蓝色存储时,我就这样做了

let storageAccount : AZSCloudStorageAccount;
            try! storageAccount = AZSCloudStorageAccount(fromConnectionString: config.getAzureConnection())

            let blobClient = storageAccount.getBlobClient()

            var container : AZSCloudBlobContainer = (blobClient.containerReference(fromName: config.getImagesContainer()))

            modelName = UIDevice.current.modelName
            let ticks = Date().timeIntervalSince1970 * 1000
            let imageName: String = "\(modelName)-\(ticks).png"

            let blob: AZSCloudBlockBlob = container.blockBlobReference(fromName: imageName)
            let imageData = UIImagePNGRepresentation(pickedImage)

            blob.upload(from: imageData!, completionHandler:{(NSError) -> Void in

            })

但是在azure存储中,使用application / octet-stream而不是image / PNG保存的内容类型。如何上传图片时更改内容类型?

1 个答案:

答案 0 :(得分:3)

blob对象应该有一个名为“Properties”的属性。应该是这样的;

blob.Properties.ContentType =“image / png”;