First add the riak-erlang-client to Nitrogen as a Plugin using rebar. Add a dependency like the one below to the rebar.config in your project. Basho resource
{deps, [
{riakc, "1.4.1",
{git, "git://github.com/basho/riak-erlang-client",
{tag, "1.4.1"}}}
]}.
Then run make in your application
cd ../../myapp
make
Upload the file using for example this Nitrogen upload example. The source code if found here.
In the finish_upload_event section capture the LocalFileName file path in the scratch folder. Use the file path to read the file.
event(_) -> ok.
start_upload_event(Tag) ->
wf:flash(wf:f("Upload started with tag (~p)", [Tag])).
finish_upload_event(_Tag, undefined, _, _) ->
wf:flash("Please select a file."), ok;
finish_upload_event(_Tag, _FileName, LocalFileName, _Node) ->
{ok, Binary_image} = file:read_file(LocalFileName),
%% Open a connection to the Riak database
{ok, Pid} = riakc_pb_socket:start(DBNode,PORT,{connect_timeout,TIMEOUT},auto_reconnect, false}])).
%% If the bucket where you save your images is called my_images, create the riak object
Obj = riakc_obj:new(term_to_binary(my_images),term_to_binary(My_key),Binary_image),
%% Save to the database
ok = riakc_pb_socket:put(Pid, Obj,[]).
To read the image from the database and display it in the web browser
-module(image).
-include_lib("nitrogen_core/include/wf.hrl").
-compile(export_all).
main() ->
%% Set the content-type of the image
wf:content_type("image/png"),
{ok, Pid} = riakc_pb_socket:start(DBNode,PORT,{connect_timeout,TIMEOUT},auto_reconnect, false}])).
%% Read the image data from the database
{ok, Fetched} = riakc_pb_socket:get(Pid, term_to_binary(my_images),term_to_binary(My_key),[]),
%% Record the image record
Binary_image = binary_to_term(riakc_obj:get_value(Fetched)),
Binary_image.
event(_) -> ok.
In the browser structure your URL to the image file like http://example.com/image
Where image is the module rendering the image file.