Skip to content

Commit

Permalink
Fix PutObjectAsync handling of unknown size streams (#271)
Browse files Browse the repository at this point in the history
Handle zero byte streams passed to PutObjectAsync with size -1
(unknown size stream) by uploading a single part with 0 bytes
before completing the multipart upload.
  • Loading branch information
poornas authored and kannappanr committed Jan 13, 2019
1 parent a206751 commit b2d9710
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
41 changes: 40 additions & 1 deletion Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public static void Main(string[] args)
PutObject_Test5(minioClient).Wait();
PutObject_Test6(minioClient).Wait();
PutObject_Test7(minioClient).Wait();
PutObject_Test8(minioClient).Wait();

// Test StatObject function
StatObject_Test1(minioClient).Wait();
Expand Down Expand Up @@ -662,7 +663,7 @@ private async static Task PutObject_Test7(MinioClient minio)
{"objectName",objectName},
{"contentType", contentType},
{"data","1MB"},
{"size","1MB"},
{"size","-1"},
};
try
{
Expand All @@ -689,6 +690,44 @@ await minio.PutObjectAsync(bucketName,
new MintLogger("PutObject_Test7",putObjectSignature1,"Tests whether PutObject with unknown stream-size passes",TestStatus.FAIL,(DateTime.Now - startTime),"",ex.Message, ex.ToString(), args).Log();
}
}
private async static Task PutObject_Test8(MinioClient minio)
{
DateTime startTime = DateTime.Now;
string bucketName = GetRandomName(15);
string objectName = GetRandomName(10);
string contentType = "application/octet-stream";
Dictionary<string,string> args = new Dictionary<string,string>
{
{ "bucketName", bucketName},
{"objectName",objectName},
{"contentType", contentType},
{"data","0B"},
{"size","-1"},
};
try
{
// Putobject call where unknown stream sent 0 bytes.
await Setup_Test(minio, bucketName);
using (System.IO.MemoryStream filestream = rsg.GenerateStreamFromSeed(0))
{
long size = -1;
long file_write_size = filestream.Length;

await minio.PutObjectAsync(bucketName,
objectName,
filestream,
size,
contentType);
await minio.RemoveObjectAsync(bucketName, objectName);
await TearDown(minio, bucketName);
}
new MintLogger("PutObject_Test8",putObjectSignature1,"Tests PutObject where unknown stream sends 0 bytes",TestStatus.PASS,(DateTime.Now - startTime), args:args).Log();
}
catch (Exception ex)
{
new MintLogger("PutObject_Test8",putObjectSignature1,"Tests PutObject where unknown stream sends 0 bytes",TestStatus.FAIL,(DateTime.Now - startTime),"",ex.Message, ex.ToString(), args).Log();
}
}
private async static Task PutGetStatEncryptedObject_Test1(MinioClient minio)
{
DateTime startTime = DateTime.Now;
Expand Down
2 changes: 1 addition & 1 deletion Minio/ApiEndpoints/ObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ await GetObjectAsync(bucketName, objectName, (stream) =>
for (partNumber = 1; partNumber <= partCount; partNumber++)
{
byte[] dataToCopy = ReadFull(data, (int)partSize);
if (dataToCopy == null)
if (dataToCopy == null && numPartsUploaded > 0)
{
break;
}
Expand Down

0 comments on commit b2d9710

Please sign in to comment.