Skip to content

Commit

Permalink
Use XML export of simple forms of riak_cs_xml:to_xml in multipart upl…
Browse files Browse the repository at this point in the history
…oads
  • Loading branch information
shino committed Feb 12, 2014
1 parent 84a821c commit d35d74a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions src/riak_cs_wm_bucket_uploads.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ to_xml(RD, Ctx=#context{local_context=LocalCtx,
{ok, {Ds, Commons}} ->
Us = [{'Upload',
[
{'Key', [unicode:characters_to_list(D?MULTIPART_DESCR.key, unicode)]},
{'UploadId', [binary_to_list(base64url:encode(D?MULTIPART_DESCR.upload_id))]},
{'Key', [D?MULTIPART_DESCR.key]},
{'UploadId', [base64url:encode(D?MULTIPART_DESCR.upload_id)]},
{'Initiator', % TODO: replace with ARN data?
[{'ID', [D?MULTIPART_DESCR.owner_key_id]},
{'DisplayName', [D?MULTIPART_DESCR.owner_display]}
Expand All @@ -90,27 +90,27 @@ to_xml(RD, Ctx=#context{local_context=LocalCtx,
Cs = [{'CommonPrefixes',
[
% WTH? The pattern [Common | _] can never match the type []
{'Prefix', [binary_to_list(Common)]}
{'Prefix', [Common]}
]} || Common <- Commons],
Get = fun(Name) -> case proplists:get_value(Name, Opts) of
undefined -> [];
X -> binary_to_list(X)
X -> X
end
end,
XmlDoc = {'ListMultipartUploadsResult',
[{'xmlns', "http://s3.amazonaws.com/doc/2006-03-01/"}],
[
{'Bucket', [binary_to_list(Bucket)]},
{'Bucket', [Bucket]},
{'KeyMarker', [Get(key_marker)]},
{'NextKeyMarker', []}, % TODO
{'NextUploadIdMarker', [Get(upload_id_marker)]},
{'Delimiter', [Get(delimiter)]},
{'Prefix', [Get(prefix)]},
{'MaxUploads', ["1000"]}, % TODO
{'MaxUploads', [1000]}, % TODO
{'IsTruncated', ["false"]} % TODO
] ++ Us ++ Cs
},
Body = riak_cs_xml:export_xml([XmlDoc]),
Body = riak_cs_xml:to_xml([XmlDoc]),
{Body, RD, Ctx};
{error, Reason} ->
riak_cs_s3_response:api_error(Reason, RD, Ctx)
Expand Down
8 changes: 4 additions & 4 deletions src/riak_cs_wm_object_upload.erl
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ process_post(RD, Ctx=#context{local_context=LocalCtx,
XmlDoc = {'InitiateMultipartUploadResult',
[{'xmlns', "http://s3.amazonaws.com/doc/2006-03-01/"}],
[
{'Bucket', [binary_to_list(Bucket)]},
{'Key', [unicode:characters_to_list(list_to_binary(Key), unicode)]},
{'UploadId', [binary_to_list(base64url:encode(UploadId))]}
{'Bucket', [Bucket]},
{'Key', [Key]},
{'UploadId', [base64url:encode(UploadId)]}
]
},
Body = riak_cs_xml:export_xml([XmlDoc]),
Body = riak_cs_xml:to_xml([XmlDoc]),
RD2 = wrq:set_resp_body(Body, RD),
{true, RD2, Ctx};
{error, Reason} ->
Expand Down
26 changes: 13 additions & 13 deletions src/riak_cs_wm_object_upload_part.erl
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ process_post(RD, Ctx=#context{local_context=LocalCtx,
[{'xmlns', "http://s3.amazonaws.com/doc/2006-03-01/"}],
[
{'Location', [lists:append(["http://", binary_to_list(Bucket), ".s3.amazonaws.com/", Key])]},
{'Bucket', [binary_to_list(Bucket)]},
{'Key', [unicode:characters_to_list(list_to_binary(Key), unicode)]},
{'ETag', [binary_to_list(UploadId64)]}
{'Bucket', [Bucket]},
{'Key', [Key]},
{'ETag', [UploadId64]}
]
},
XmlBody = riak_cs_xml:export_xml([XmlDoc]),
XmlBody = riak_cs_xml:to_xml([XmlDoc]),
RD2 = wrq:set_resp_body(XmlBody, RD),
{true, RD2, Ctx};
{error, notfound} ->
Expand Down Expand Up @@ -281,10 +281,10 @@ to_xml(RD, Ctx=#context{local_context=LocalCtx,
{ok, Ps} ->
Us = [{'Part',
[
{'PartNumber', [integer_to_list(P?PART_DESCR.part_number)]},
{'PartNumber', [P?PART_DESCR.part_number]},
{'LastModified', [P?PART_DESCR.last_modified]},
{'ETag', [riak_cs_utils:etag_from_binary(P?PART_DESCR.etag)]},
{'Size', [integer_to_list(P?PART_DESCR.size)]}
{'Size', [P?PART_DESCR.size]}
]
} || P <- lists:sort(Ps)],
PartNumbers = [P?PART_DESCR.part_number || P <- Ps],
Expand All @@ -295,9 +295,9 @@ to_xml(RD, Ctx=#context{local_context=LocalCtx,
XmlDoc = {'ListPartsResult',
[{'xmlns', "http://s3.amazonaws.com/doc/2006-03-01/"}],
[
{'Bucket', [binary_to_list(Bucket)]},
{'Key', [unicode:characters_to_list(list_to_binary(Key), unicode)]},
{'UploadId', [binary_to_list(base64url:encode(UploadId))]},
{'Bucket', [Bucket]},
{'Key', [Key]},
{'UploadId', [base64url:encode(UploadId)]},
{'Initiator', % TODO: replace with ARN data?
[{'ID', [UserKeyId]},
{'DisplayName', [UserDisplay]}
Expand All @@ -307,13 +307,13 @@ to_xml(RD, Ctx=#context{local_context=LocalCtx,
{'DisplayName', [UserDisplay]}
]},
{'StorageClass', ["STANDARD"]}, % TODO
{'PartNumberMarker', ["1"]}, % TODO
{'NextPartNumberMarker', [integer_to_list(MaxPartNumber)]}, % TODO
{'MaxParts', [integer_to_list(length(Us))]}, % TODO
{'PartNumberMarker', [1]}, % TODO
{'NextPartNumberMarker', [MaxPartNumber]}, % TODO
{'MaxParts', [length(Us)]}, % TODO
{'IsTruncated', ["false"]} % TODO
] ++ Us
},
Body = riak_cs_xml:export_xml([XmlDoc]),
Body = riak_cs_xml:to_xml([XmlDoc]),
{Body, RD, Ctx};
{error, notfound} ->
riak_cs_s3_response:no_such_upload_response(UploadId, RD, Ctx);
Expand Down

0 comments on commit d35d74a

Please sign in to comment.