Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 40 lines (34 sloc) 1.481 kb
3162e52 Grant Schofield initial commit to riak_function_contrib
schofield authored
1 %% -------------------------------------------------------------------
2 %%
3 %%
4 %% This file is provided to you under the Apache License,
5 %% Version 2.0 (the "License"); you may not use this file
6 %% except in compliance with the License. You may obtain
7 %% a copy of the License at
8 %%
9 %% http://www.apache.org/licenses/LICENSE-2.0
10 %%
11 %% Unless required by applicable law or agreed to in writing,
12 %% software distributed under the License is distributed on an
13 %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 %% KIND, either express or implied. See the License for the
15 %% specific language governing permissions and limitations
16 %% under the License.
17 %%
18 %% -------------------------------------------------------------------
19
20 -module(bucket_importer).
21
22 -export([import_data/4]).
23
24
25
26 import_data(ToServer, Bucket, Directory, ContentType) ->
27 {ok, Client} = riak:client_connect(ToServer),
28 FL = filelib:fold_files(Directory, ".*", true, fun(F, L) -> [F|L] end, []),
b160bb9 fp Removed the list_to_binary() for ContenType. Content Types *should* be l...
fakepop authored
29 [ load_data(F, Client, list_to_binary(Bucket), ContentType) || F <- FL ].
3162e52 Grant Schofield initial commit to riak_function_contrib
schofield authored
30
31 load_data(FName, Client, Bucket, ContentType) ->
32 case file:read_file(FName) of
33 {ok, Data} ->
34 Key = list_to_binary(filename:basename(FName, filename:extension(FName))),
35 Object = riak_object:new(Bucket, Key, Data, ContentType),
36 Client:put(Object, 1),
37 io:format(".");
38 {error, Reason} ->
39 io:format("Error reading ~p:~p~n", [FName, Reason])
40 end.
Something went wrong with that request. Please try again.