Last active
September 28, 2017 13:44
-
-
Save copenhas/677cf1b1066af1c53fce9feaa9ff0191 to your computer and use it in GitHub Desktop.
Moto hash error when using S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Microsoft Windows 7 Professional |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment