Simplify S3 object name generation
The previous design used an extremely long prefix including a forward slash that could have made managing uploaded objects extremely difficult for operators.
This commit is contained in:
parent
7c58c7aa0a
commit
5c7ec06224
|
@ -447,16 +447,8 @@ object_url(BucketURL, FileName) ->
|
||||||
FileName :: binary()
|
FileName :: binary()
|
||||||
) ->
|
) ->
|
||||||
ObjectName :: binary().
|
ObjectName :: binary().
|
||||||
% generate a unique-in-time object name. the name consists of a hash
|
% generate reasonably unique sortable (by time first) object name.
|
||||||
% derived from the file, node, time, and a random number, a
|
|
||||||
% forward-slash, and the original filename. this ensures that it does
|
|
||||||
% not collide with other objects, while the forward slash ensures that
|
|
||||||
% the client displays only the original file name.
|
|
||||||
object_name(FileName) ->
|
object_name(FileName) ->
|
||||||
MD = crypto:hash_init(sha256),
|
str:format("~.36B~.36B-~s", [os:system_time(microsecond),
|
||||||
MDFilename = crypto:hash_update(MD, FileName),
|
erlang:phash2(node()),
|
||||||
MDNodeName = crypto:hash_update(MDFilename, atom_to_list(node())),
|
FileName]).
|
||||||
MDTime = crypto:hash_update(MDNodeName, <<(os:system_time())>>),
|
|
||||||
MDRand = crypto:hash_update(MDTime, crypto:strong_rand_bytes(256)),
|
|
||||||
Hash = crypto:hash_final(MDRand),
|
|
||||||
<<(str:to_hexlist(Hash))/binary, "/", FileName/binary>>.
|
|
||||||
|
|
Loading…
Reference in New Issue