Skip to content

Instantly share code, notes, and snippets.

@copenhas
Last active September 28, 2017 13:44
Show Gist options
  • Save copenhas/677cf1b1066af1c53fce9feaa9ff0191 to your computer and use it in GitHub Desktop.
Save copenhas/677cf1b1066af1c53fce9feaa9ff0191 to your computer and use it in GitHub Desktop.
Moto hash error when using S3
import hashlib
def go():
md5 = hashlib.md5()
contents = open('c:\\windows-version.txt').read()
encoded = contents.encode("utf-8")
md5.update(encoded)
hash_value = md5.hexdigest()
return hash_value
print('"{0}"'.format(go()))
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AWSSDK.Core" version="3.3.17.9" targetFramework="net461" />
<package id="AWSSDK.S3" version="3.3.11" targetFramework="net461" />
</packages>
using System;
using System.IO;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Amazon.S3;
using Amazon.S3.Model;
namespace moto_test
{
class Program
{
static void Main(string[] args)
{
TestClientAsync().GetAwaiter().GetResult();
}
static async Task TestClientAsync()
{
using (var md5 = new MD5CryptoServiceProvider())
{
var contents = File.ReadAllText("c:\\windows-version.txt");
var encoded = Encoding.UTF8.GetBytes(contents);
var hash = md5.ComputeHash(encoded);
var etag = BitConverter.ToString(hash).Replace("-", string.Empty);
Console.WriteLine($".NET MD5: \"{etag}\"");
}
var client = new AmazonS3Client(new AmazonS3Config
{
ServiceURL = "http://localhost:5000"
});
await client.PutBucketAsync("MotoTest");
var bucketsResponse = await client.ListBucketsAsync();
foreach (var bucket in bucketsResponse.Buckets)
{
Console.WriteLine(bucket.BucketName);
}
try
{
var putResponse = await client.PutObjectAsync(new PutObjectRequest
{
BucketName = "MotoTest",
Key = "my-file.txt",
FilePath = "c:\\windows-version.txt"
});
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
var getResponse = await client.GetObjectAsync(new GetObjectRequest
{
BucketName = "MotoTest",
Key = "my-file.txt"
});
Console.WriteLine($"Moto MD5: {getResponse.ETag}");
Console.ReadKey();
}
}
}
Microsoft Windows 7 Professional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment