S3-MultiPartAPI を使用すると、例外が発生します。
"{"提案されたアップロードは、許可されている最小サイズよりも小さい"}"
これを 11MB と 7MB の 2 つのファイルでテストします。1MBあれば問題なく使えます。
FileStream fs = new FileStream(foo, FileAccess.ReadWrite);
fs.CopyTo(new S3Tools.S3CopyMemoryStream("bar", new byte[Buffersize + Buffersize/2], transferUtility));
そして、構成 utilityConfig.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();
}
}
これが Upload イベントです。この行で例外が発生します。
CompleteMultipartUploadResponse completeMultipartUploadResponse = 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;
}
}
問題は何ですか?