我必须在这里遗漏一些明显的东西,但我发现自己无法进行我认为合法的向上转换。我正在尝试将数据上传到 Azure 中的 Blob 存储,并希望使用CloudBlob.UploadText(string)方法。但是,当我访问我的 blob 时,我得到了一个CloudBlockBlob实例,据我所知,它继承自 CloudBlob,并且方法 UploadText 不可访问,所以我尝试let blob = targetBlob :> CloudBlob
了 - 惨遭失败,并显示消息
SmallScript.fsx(28,12): error FS0193: Type constraint mismatch. The type
CloudBlockBlob
is not compatible with type
CloudBlob
The type 'CloudBlockBlob' is not compatible with the type 'CloudBlob'
我可以使用 UploadFromStream 上传数据,但 UploadText 对我的目的来说非常方便。谁能帮我看看我错过了什么?
作为记录,如果这有帮助,这里是有效的代码:
let credentials = StorageCredentials(accountName, accountKey)
let storageAccount = CloudStorageAccount(credentials, true)
let client = storageAccount.CreateCloudBlobClient()
let containerName = "numerics"
let container = client.GetContainerReference(containerName)
container.CreateIfNotExists() |> ignore
let targetBlobName = "MiniSparseMatrix.csv"
let targetBlob = container.GetBlockBlobReference(targetBlobName)
let fileLocation = @"C:\Users\Mathias\Desktop\TestMatrix.txt"
let stream = System.IO.File.OpenRead(fileLocation)
targetBlob.UploadFromStream(stream)
stream.Close()