Skip to content

Commit

Permalink
feat: allow specifying content type when creating append blob
Browse files Browse the repository at this point in the history
  • Loading branch information
thalesmg committed May 17, 2024
1 parent 4cf05d7 commit 4b072a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/erlazure.erl
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,11 @@ handle_call({put_blob, Container, Name, Type = append_blob, Options}, _From, Sta
ReqOptions = [{method, put},
{path, lists:concat([Container, "/", Name])},
{params, Params ++ Options}],
ReqContext = new_req_context(?blob_service, ReqOptions, State),
ReqContext1 = new_req_context(?blob_service, ReqOptions, State),
ReqContext = case proplists:get_value(content_type, Options) of
undefined -> ReqContext1#req_context{ content_type = "application/octet-stream" };
ContentType -> ReqContext1#req_context{ content_type = ContentType }
end,

{Code, Body} = execute_request(ServiceContext, ReqContext),
return_response(Code, Body, State, ?http_created, created);
Expand Down
8 changes: 6 additions & 2 deletions test/erlazure_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,16 @@ t_append_blob_smoke_test(Config) ->
?assertMatch({[], _}, erlazure:list_containers(Pid)),
?assertMatch({ok, created}, erlazure:create_container(Pid, Container)),
%% Upload some blobs
?assertMatch({ok, created}, erlazure:put_append_blob(Pid, Container, "blob1")),
Opts = [{content_type, "text/csv"}],
?assertMatch({ok, created}, erlazure:put_append_blob(Pid, Container, "blob1", Opts)),
?assertMatch({ok, appended}, erlazure:append_block(Pid, Container, "blob1", <<"1">>)),
?assertMatch({ok, appended}, erlazure:append_block(Pid, Container, "blob1", <<"\n">>)),
?assertMatch({ok, appended}, erlazure:append_block(Pid, Container, "blob1", <<"2">>)),
ListedBlobs = erlazure:list_blobs(Pid, Container),
?assertMatch({[#cloud_blob{name = "blob1"}], _},
erlazure:list_blobs(Pid, Container)),
ListedBlobs),
{[#cloud_blob{name = "blob1", properties = BlobProps}], _} = ListedBlobs,
?assertMatch(#{content_type := "text/csv"}, maps:from_list(BlobProps)),
%% Read back data
?assertMatch({ok, <<"1\n2">>}, erlazure:get_blob(Pid, Container, "blob1")),
%% Delete blob
Expand Down

0 comments on commit 4b072a0

Please sign in to comment.