奇怪突发错误"要被写入的字节数大于指定CONTENTLENGTH&QUOT越大; [英] Strange Sudden Error "The number of bytes to be written is greater than the specified ContentLength"

查看:319
本文介绍了奇怪突发错误"要被写入的字节数大于指定CONTENTLENGTH&QUOT越大;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上传的位图图像天青Blob存储。这是所有工作正常,但后来我做了一个新的项目使用相同的code,但现在,我一直得到这个错误
要被写入的字节数大于指定CONTENTLENGTH大

I'm uploading bitmap images to Azure Blob Storage. It was all working fine, but then I made a new project to use the same code but now I get this error consistently "The number of bytes to be written is great than the specified ContentLength"

下面是我的code的一部分
memoryStream.Seek(0,SeekOrigin.Begin);

Here's part of my code memoryStream.Seek(0, SeekOrigin.Begin);

try
{
    cloudBlobContainer.GetBlockBlobReference(resourcename).UploadFromStream(memoryStream);

    return true;
}
catch (Exception exception)
{
    ReportHelper.Report(Tag, "Error occurred while uploading image " + imageQuality, true, exception, true);

    return null;
}

问题是在UploadFromStream功能,我不知道为什么它不工作了。

The problem is in the UploadFromStream function, I don't know why it doesn't work anymore.

这UploadFromStream在这个DLL中引用 https://github.com/zgramana/IOSAzureBlobUploader // github上:/树/主/ lib目录是从该解决方案 HTTPS构建 .COM / zgramana / Azure的SDK换网

This UploadFromStream is referenced in this dll https://github.com/zgramana/IOSAzureBlobUploader/tree/master/lib which is built from this solution https://github.com/zgramana/azure-sdk-for-net

下面是这是从DLL中引用的UploadFromStream()函数

Here's the UploadFromStream() function which is referenced from the dll

/// <summary>
/// Uploads a stream to a block blob. 
/// </summary>
/// <param name="source">The stream providing the blob content.</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the blob. If <c>null</c>, no condition is used.</param>
/// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies any additional options for the request.</param>
/// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
[DoesServiceRequest]
public void UploadFromStream(Stream source, AccessCondition accessCondition = null, BlobRequestOptions options = null, OperationContext operationContext = null)
{
    CommonUtils.AssertNotNull("source", source);
    this.attributes.AssertNoSnapshot();
    BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.BlockBlob, this.ServiceClient);
    operationContext = operationContext ?? new OperationContext();

    DateTime? expiryTime = modifiedOptions.MaximumExecutionTime.HasValue
        ? DateTime.Now + modifiedOptions.MaximumExecutionTime.Value
        : (DateTime?)null;

    if ((this.ServiceClient.ParallelOperationThreadCount == 1) &&
        source.CanSeek &&
        ((source.Length - source.Position) <= this.ServiceClient.SingleBlobUploadThresholdInBytes))
    {
        string contentMD5 = null;
        if (modifiedOptions.StoreBlobContentMD5.Value)
        {
            OperationContext tempOperationContext = new OperationContext();
            StreamDescriptor streamCopyState = new StreamDescriptor();
            long startPosition = source.Position;
            source.WriteToSync(Stream.Null, null /* maxLength */, expiryTime, true, true, tempOperationContext, streamCopyState);
            source.Position = startPosition;
            contentMD5 = streamCopyState.Md5;
        }

        Executor.ExecuteSync(
            this.PutBlobImpl(source, contentMD5, accessCondition, modifiedOptions),
            modifiedOptions.RetryPolicy,
            operationContext);
    }
    else
    {
        using (Stream blobStream = this.OpenWrite(accessCondition, modifiedOptions, operationContext))
        {
            source.WriteToSync(blobStream, null /* maxLength */, expiryTime, false, true, new OperationContext(), null /* streamCopyState */);
        }
    }
}

我一直在做研究的时间试图找出如何解决这个错误,但不能。我没有明确设定在CONTENTLENGTH价值呢(其实不管我甚至不能够访问它,因为UploadFromStream做它本身我相信)

I've been doing hours of research trying to figure out how to fix this error but couldn't. I am NOT explicitly setting the ContentLength value in anyway (matter of fact I don't even have access to it since UploadFromStream does it by itself I believe)

的MemoryStream的容量是2048字节,它的长度为1415字节

The capacity of memorystream is 2048 bytes, it's length is 1415 bytes

下面是错误的堆栈跟踪

{Microsoft.WindowsAzure.Storage.StorageException:字节数
  要写入大于指定CONTENTLENGTH越大。 --->
  System.Net.ProtocolViolationException:字节数是
  书面比指定CONTENTLENGTH越大。在
  System.Net.WebConnectionStream.CheckWriteOverflow(Int64的
  CONTENTLENGTH,Int64的totalWritten,Int64的大小)[0x00000]中:0在System.Net.WebConnectionStream.BeginWrite
  (System.Byte []缓冲区,偏移的Int32,的Int32大小,System.AsyncCallback
  CB,System.Object的状态)[0x00000]中:0的
  System.Net.WebConnectionStream.Write(System.Byte []缓冲区的Int32
  偏移的Int32大小)[0x00000]中:0的
  Microsoft.WindowsAzure.Storage.Core.Util.StreamExtensions.WriteToSync
  (的System.IO.Stream流的System.IO.Stream toStream,可空 1
  最大长度,可为空
1 expiryTime,布尔calculateMd5,布尔
  syncRead,Microsoft.WindowsAzure.Storage.OperationContext
  的OperationContext,
  Microsoft.WindowsAzure.Storage.Core.Util.StreamDescriptor
  streamCopyState)[0x00000]中:0的
  Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync [nulltype引起]
  (Microsoft.WindowsAzure.Storage.Core.Executor.StorageCommandBase 1
  CMD,IRetryPolicy政策,
  Microsoft.WindowsAzure.Storage.OperationContext的OperationContext)
  [0x00000]上述&lt;文件名不明&GT;:内部异常堆栈的0 ---结束
  跟踪---在
  Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync [nulltype引起]
  (Microsoft.WindowsAzure.Storage.Core.Executor.StorageCommandBase
1
  CMD,IRetryPolicy政策,
  Microsoft.WindowsAzure.Storage.OperationContext的OperationContext)
  [0x00000]中:0的
  Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStream
  (源的System.IO.Stream,
  Microsoft.WindowsAzure.Storage.AccessCondition accessCondition,
  Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions选项,
  Microsoft.WindowsAzure.Storage.OperationContext的OperationContext)
  [0x00000]中:0的
  Client.Mobile.Droid.Source.Azure.AmsHelper + d__6.MoveNext
  ()[0x0021b]在C:\\ testsolution \\ AmsHelper.cs:103请求
  InformationRequestID:RequestDate:StatusMessage:}

{Microsoft.WindowsAzure.Storage.StorageException: The number of bytes to be written is greater than the specified ContentLength. ---> System.Net.ProtocolViolationException: The number of bytes to be written is greater than the specified ContentLength. at System.Net.WebConnectionStream.CheckWriteOverflow (Int64 contentLength, Int64 totalWritten, Int64 size) [0x00000] in :0 at System.Net.WebConnectionStream.BeginWrite (System.Byte[] buffer, Int32 offset, Int32 size, System.AsyncCallback cb, System.Object state) [0x00000] in :0 at System.Net.WebConnectionStream.Write (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in :0 at Microsoft.WindowsAzure.Storage.Core.Util.StreamExtensions.WriteToSync (System.IO.Stream stream, System.IO.Stream toStream, Nullable1 maxLength, Nullable1 expiryTime, Boolean calculateMd5, Boolean syncRead, Microsoft.WindowsAzure.Storage.OperationContext operationContext, Microsoft.WindowsAzure.Storage.Core.Util.StreamDescriptor streamCopyState) [0x00000] in :0 at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[NullType] (Microsoft.WindowsAzure.Storage.Core.Executor.StorageCommandBase1 cmd, IRetryPolicy policy, Microsoft.WindowsAzure.Storage.OperationContext operationContext) [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[NullType] (Microsoft.WindowsAzure.Storage.Core.Executor.StorageCommandBase1 cmd, IRetryPolicy policy, Microsoft.WindowsAzure.Storage.OperationContext operationContext) [0x00000] in :0 at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStream (System.IO.Stream source, Microsoft.WindowsAzure.Storage.AccessCondition accessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions options, Microsoft.WindowsAzure.Storage.OperationContext operationContext) [0x00000] in :0 at Client.Mobile.Droid.Source.Azure.AmsHelper+d__6.MoveNext () [0x0021b] in c:\testsolution\AmsHelper.cs:103 Request InformationRequestID:RequestDate:StatusMessage:}

我检查的存储容器,并且流确实得到正确上传,我可以看到的图像和所有罚款,但由于某种原因,我得到这个奇怪的错误。

I've checked the storage container, and the stream does indeed get uploaded correctly, and I can see the image and all fine, but for some reason I get this strange error.

任何修复错误帮助将非常AP preciated。我可以根据要求提供的任何信息。

Any help fixing the error would be much appreciated. I can provide any info upon request.

推荐答案

我仍然无法为何出现错误弄清楚。可能是因为我使用的是一岁过时叉库上传斑点,该库甚至没有为了支持我从第一个地方使用该平台。

I still couldn't figure out why the error occurs. Probably cause I'm using a one-year-old outdated forked library to upload blobs, that library wasn't even meant to support the platform I'm using from the first place.

不管怎样,原来的斑点上传pretty细得多,因此,所有我needrf做的是燮preSS的错误

Anyway, turns out the blobs are uploaded pretty much fine, so all I needrf to do was to suppress that error

try
{
    cloudBlobContainer.GetBlockBlobReference(resourcename).UploadFromStream(memoryStream);

    return true;
}
catch (Microsoft.WindowsAzure.Storage.StorageException storageException)
{
    return true;
}
catch (System.Net.ProtocolViolationException protocolViolationException)
{
    return true;
}
catch (Exception exception)
{
    ReportHelper.Report(Tag, "Error occurred while uploading image " + imageQuality, true, exception, true);

    return null;
}

这篇关于奇怪突发错误&QUOT;要被写入的字节数大于指定CONTENTLENGTH&QUOT越大;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆