swift - 将图像上传到 Azure 存储

标签 swift azure

当我将图像上传到 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。上传图片时如何更改内容类型?

最佳答案

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

blob.Properties.ContentType = "image/png";

关于swift - 将图像上传到 Azure 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43982079/

相关文章:

swift - DispatchQueue中async的含义

ios - AudioKit:如何使 AnalogSynthX-Example 的旋钮呈指数而不是线性?

ios - Branch.io:添加的元数据参数未获取路由:IOS Deep Link

azure - 使用 AzCopy 将数据从一个存储帐户复制到另一个存储帐户?

azure - HTTP 错误 500.30 - 新创建的应用服务的 ANCM 进程内启动失败

javascript - JavaScript Azure Function 中的 if 语句不起作用

swift - RxSwift 为什么我们在不调用 dispose 的情况下会发生内存泄漏

swift - 我应该在 Swift 中使用 Array 还是 NSArray

备份到 Azure 存储 BLOB 时出现 SQLVDI 错误

azure - Swagger UI 页面的隔离 Azure Function 绕过身份验证中间件