Reputation: 57916
I am trying to upload an image to Amazon S3 using C#:
PutObjectRequest titledRequest = null;
S3Response response = null;
using (var memoryStream = new MemoryStream())
{
image.Save(memoryStream, ImageFormat.Png);
titledRequest = new PutObjectRequest();
titledRequest.WithBucketName(bucketName)
.WithKey(keyName)
.WithCannedACL(S3CannedACL.PublicRead)
.WithInputStream(memoryStream);
response = client.PutObject(titledRequest);
}
As you can see, I am not saving the image file locally but rather streaming it to S3. However, for some reason, this process takes around 50 seconds for a 50kb file!
There is nothing wrong with my upload speed its well over 1mbps.
I'm wondering is it faster to save the file first and upload?
Is there anything I should consider to speed up upload process? Again, no problems on the broadband side of things!
Upvotes: 3
Views: 1435
Reputation: 54128
Amazon docs say:
If uploading from an input stream, always specify metadata with the content size set. Otherwise the contents of the input stream have to be buffered in memory before being sent to Amazon S3. This can cause very negative performance impacts.
Hard to believe this could be your problem, but a best practice you should follow.
Other things to consider -
Upvotes: 5