gpt4 book ai didi

Azure Blob - 调用 UploadFile() 时出现 ArgumentNullException

转载 作者:行者123 更新时间:2023-12-01 09:32:56 26 4
gpt4 key购买 nike

尝试使用以下代码上传文件时出现以下异常:

            string encodedUrl = "videos/Sample.mp4"
CloudBlockBlob encodedVideoBlob = blobClient.GetBlockBlobReference(encodedUrl);
Log(string.Format("Got blob reference for {0}", encodedUrl), EventLogEntryType.Information);
encodedVideoBlob.Properties.ContentType = contentType;
encodedVideoBlob.Metadata[BlobProperty.Description] = description;
encodedVideoBlob.UploadFile(localEncodedBlobPath);

我看到“获取 blob 引用”消息,因此我假设该引用解析正确。

Void Run() C:\Inter\Projects\PoC\WorkerRole\WorkerRole.cs (40)
System.ArgumentNullException: Value cannot be null.
Parameter name: value
at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait()
at Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(Stream source, BlobRequestOptions options)
at Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFile(String fileName, BlobRequestOptions options)
at EncoderWorkerRole.WorkerRole.ProcessJobOutput(IJob job, String videoBlobToEncodeUrl) in C:\Inter\Projects\PoC\WorkerRole\WorkerRole.cs:line 144
at EncoderWorkerRole.WorkerRole.Run() in C:\Inter\Projects\PoC\WorkerRole\WorkerRole.cs:line 40

有趣的是,我从本地服务器(即 Azure 外部)运行相同的代码片段,并且它运行正常。

欢迎提出想法,谢谢!

最佳答案

找到了罪魁祸首!

基本上,问题出在这一行

encodedVideoBlob.Metadata[BlobProperty.Description] = 描述;

下面有一个检查孔,可确保未设置 null 或空元数据。通过从 Reflector 反汇编并搜索 ArgumentNullException 发生情况找到了它。

如果能够捕获并在堆栈中重新抛出更有意义的异常,那就太好了:-)

以下是有趣的方法:

internal static void AddMetadata(HttpWebRequest request, NameValueCollection metadata)
{
if (metadata != null)
{
foreach (string str in metadata.AllKeys)
{
AddMetadata(request, str, metadata[str]);
}
}
}

internal static void AddMetadata(HttpWebRequest request, string name, string value)
{
CommonUtils.AssertNotNullOrEmpty("value", value);
request.Headers.Add("x-ms-meta-" + name, value);
}


internal static void AssertNotNullOrEmpty(string paramName, string value)
{
AssertNotNull(paramName, value);
if (string.IsNullOrEmpty(value))
{
throw new ArgumentException(Microsoft.WindowsAzure.SR.ArgumentEmptyError, paramName);
}
}

internal static void AssertNotNull(string paramName, object value)
{
if (value == null)
{
throw new ArgumentNullException(paramName);
}
}

关于Azure Blob - 调用 UploadFile() 时出现 ArgumentNullException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13017326/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com