Using the S3-MultiPartAPI i get an exception:
"{"Your proposed upload is smaller than the minimum allowed size"}"
I test this with 2 files 11MB and 7MB. With 1MB it works without problems.
FileStream fs = new FileStream(foo, FileAccess.ReadWrite);
fs.CopyTo(new S3Tools.S3CopyMemoryStream("bar", new byte[Buffersize + Buffersize/2], transferUtility));
And i set the configuration utilityConfig.MinSizeBeforePartUpload to 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();
}
}
This is the Uploadevent. In this line i get the exception.
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;
}
}
Any suggestions what the problem is?