About File Version sha1 hash
Hi everyone,
Now I am developing custom app using Box API with Python SDK.
I want to discover when the file or folder edited or got some user's action.
The response of File Version API includes some data that my app could notice modified.
However I'm not sure the sha1 hash was generated from what.
Also the difference of " modified_at" and "content_modified_at" fields.
Please let me know.
Thank you.
-
Hi ,
Here's the difference between modified at and content modified at:
- content_modified_at: The last time the content was modified, which may predate when it was first uploaded to Box (if it was modified locally on another system).
- modified_at: The last time the content was modified since being uploaded into Box, not taking into account modifications before being uploaded to Box.
The SHA1 is auto-generated based on the content uploaded into Box, and may be used to compare against a SHA1 of the local file.
- Jon
-
/* Cut-and-pasting relevant snippets from what I have. This is how I do it in C#. You may have to google how the SHA1Managed object does it. It returns the same sha1 string as the Box sha1. */
using SSC = System.Security.Cryptography;
using SI = System.IO;public static string GetSha1HashOfFile(string pathToFile)
{
using (SSC.SHA1Managed sha1 = new SSC.SHA1Managed())
{
using (SI.FileStream stream = SI.File.OpenRead(pathToFile))
{
return GetSha1Hash(sha1, stream);
}
}
}public static string GetSha1Hash(SSC.SHA1Managed sha1, SI.Stream stream)
{
byte[] hash = sha1.ComputeHash(stream);
return HashByteArrayToString(hash);
}public static string HashByteArrayToString(byte[] hashByteArray)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(hashByteArray.Length * 2);
foreach (byte b in hashByteArray)
{
// can be "x2" if you want lowercase
sb.Append(b.ToString("X2"));
}
return sb.ToString();
}
サインインしてコメントを残してください。
コメント
2件のコメント