使用 S3-MultiPartAPI,我得到一个异常:
"{"您建议的上传小于允许的最小大小"}"
我用 2 个文件 11MB 和 7MB 对此进行了测试。使用1MB,它可以毫无问题地工作。
FileStream fs = new FileStream(foo, FileAccess.ReadWrite);
司 司长。CopyTo(new S3Tools.S3CopyMemoryStream("bar", new byte[Buffersize + Buffersize/2], transferUtility));
我将配置实用程序Config.MinSizeBeforePartUpload设置为2。
public class S3CopyMemoryStream : MemoryStream
{
private string _key;
private byte[] _buffer;
private S3TransferUtility _transferUtility;
public StartUploadS3CopyFileStreamEvent StartUploadS3FileStreamEvent { get; set; }
public int WriteCount { get; private set; }
public bool EndOfPart { get; private set; }
public bool InitiatingPart { get; private set; }
public string UploadPartId { get; set; }
public List<PartETag> PartETagCollection { get; set; }
public S3CopyMemoryStream WithS3CopyFileStreamEvent(StartUploadS3CopyFileStreamEvent doing)
{
S3CopyMemoryStream s3CopyStream = new S3CopyMemoryStream(this._key, this._buffer, this._transferUtility);
s3CopyStream.StartUploadS3FileStreamEvent = new S3CopyMemoryStream.StartUploadS3CopyFileStreamEvent(CreateMultiPartS3Blob);
return s3CopyStream;
}
public S3CopyMemoryStream(string key, byte[] buffer, S3TransferUtility transferUtility)
: base(buffer)
{
InitiatingPart = true;
EndOfPart = false;
WriteCount = 1;
PartETagCollection = new List<PartETag>();
QueueWithIncompleteParts = new Queue<int>();
_buffer = buffer;
_key = key;
_transferUtility = transferUtility;
}
public delegate void StartUploadS3CopyFileStreamEvent(S3TransferUtility transferUtility, string key, S3CopyMemoryStream stream);
public override bool CanSeek
{
get { return false; }
}
public override void Write(byte[] array, int offset, int count)
{
base.Write(array, offset, count);
if(Position >= Buffersize)
{
if (WriteCount > 1)
InitiatingPart = false;
StartUploadS3FileStreamEvent.Invoke(_transferUtility, _key, this);
WriteCount++;
base.Flush();
base.Seek(0, SeekOrigin.Begin);
base.Flush();
}
}
public override void Close()
{
if(WriteCount > 1)
InitiatingPart = false;
EndOfPart = true;
StartUploadS3FileStreamEvent.Invoke(_transferUtility, _key, this);
base.Close();
}
}
这是上传事件。在这一行中,我得到了例外。
完成分段上传响应完成分段上传响应 = transferUtility.S3Client.CompleteMultipartUpload(completeMultipartUploadRequest);
static internal void CreateMultiPartS3Blob(S3TransferUtility transferUtility, string key, S3CopyMemoryStream stream)
{
if (stream.InitiatingPart)
{
InitiateMultipartUploadRequest initiateMultipartUploadRequest =
new InitiateMultipartUploadRequest()
.WithBucketName(transferUtility.BucketName)
.WithKey(key);
InitiateMultipartUploadResponse initiateResponse =
transferUtility.S3Client.InitiateMultipartUpload(initiateMultipartUploadRequest);
stream.UploadPartId = initiateResponse.UploadId;
}
UploadPartRequest uploadPartRequest =
new UploadPartRequest()
.WithBucketName(transferUtility.BucketName)
.WithKey(key)
.WithPartNumber(stream.WriteCount)
.WithPartSize(stream.Position)
.WithUploadId(stream.UploadPartId)
.WithInputStream(stream) as UploadPartRequest;
UploadPartResponse response = transferUtility.S3Client.UploadPart(uploadPartRequest);
PartETag etag = new PartETag(response.PartNumber, response.ETag);
stream.PartETagCollection.Add(etag);
if (stream.EndOfPart)
{
CompleteMultipartUploadRequest completeMultipartUploadRequest =
new CompleteMultipartUploadRequest()
.WithBucketName(transferUtility.BucketName)
.WithKey(key)
.WithPartETags(stream.PartETagCollection)
.WithUploadId(stream.UploadPartId);
CompleteMultipartUploadResponse completeMultipartUploadResponse =
transferUtility.S3Client.CompleteMultipartUpload(completeMultipartUploadRequest);
string loc = completeMultipartUploadResponse.Location;
}
}
任何建议是什么问题?
请求使用当前位置的流,因此我必须在上传之前将位置设置为零。
首先考虑而不是发布.. *g
问候