github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

cstar / erls3

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 7
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (5)
  • Wiki (1)
  • Graphs
  • Tree: dc2d8a1

click here to add a description

click here to add a homepage

  • Branches (2)
    • ibrowse
    • master
  • Tags (5)
    • 1.0
    • 0.9
    • 0.8
    • 0.7
    • 0.6
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Erlang/OTP application for accessing Amazon S3 — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

removed Makefile and Emakefile (autogenerated) 
cstar (author)
Mon Mar 02 12:12:53 -0800 2009
commit  dc2d8a194a5ba8b572f67186007f9c3688ebf1e1
tree    e3f5128722d4b956a0c32a7c869484ae8cf36f85
parent  e9709dc5e8d8f6bca767aaa55ce417f592ac4f38
erls3 / lib / s3 / src / s3.erl lib/s3/src/s3.erl
100644 102 lines (86 sloc) 2.704 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
%%%-------------------------------------------------------------------
%%% File : s3.erl
%%% Author : Andrew Birkett <andy@nobugs.org>
%%% Description :
%%%
%%% Created : 14 Nov 2007 by Andrew Birkett <andy@nobugs.org>
%%%-------------------------------------------------------------------
-module(s3).
 
-behaviour(application).
 
%%--------------------------------------------------------------------
%% External exports
%%--------------------------------------------------------------------
-export([
     start/0,
start/2,
shutdown/0,
stop/1
]).
%% API
-export([
list_buckets/0, create_bucket/1, delete_bucket/1,
list_objects/2, list_objects/1, write_object/4, read_object/2, delete_object/2 ]).
 
 
start()->
    crypto:start(),
    application:start(xmerl),
    inets:start(),
    application:start(s3).
    
 
start(_Type, _StartArgs) ->
    ID = get(access, "AMAZON_ACCESS_KEY_ID"),
    Secret = get(secret, "AMAZON_SECRET_ACCESS_KEY"),
    SSL = param(ssl, true),
    Timeout = param(timeout, nil),
    if SSL == true -> ssl:start();
        true -> ok
    end,
    if ID == error orelse Secret == error ->
            {error, "AWS credentials not set. Pass as application parameters or as env variables."};
        true ->
            N = param(workers, 5),
            s3sup:start_link([ID, Secret, SSL, Timeout], N)
end.
 
shutdown() ->
    application:stop(s3).
    
 
 
create_bucket (Name) ->
    Pid = s3sup:get_random_pid(),
    gen_server:call(Pid, {put, Name} ).
delete_bucket (Name) ->
    Pid = s3sup:get_random_pid(),
    gen_server:call(Pid, {delete, Name} ).
list_buckets () ->
    Pid = s3sup:get_random_pid(),
    gen_server:call(Pid, {listbuckets}).
 
write_object (Bucket, Key, Data, ContentType) ->
    Pid = s3sup:get_random_pid(),
    gen_server:call(Pid, {put, Bucket, Key, Data, ContentType}).
read_object (Bucket, Key) ->
    Pid = s3sup:get_random_pid(),
    gen_server:call(Pid, {get, Bucket, Key}).
delete_object (Bucket, Key) ->
    Pid = s3sup:get_random_pid(),
    gen_server:call(Pid, {delete, Bucket, Key}).
 
%% option example: [{delimiter, "/"},{maxresults,10},{prefix,"/foo"}]
list_objects (Bucket, Options ) ->
    Pid = s3sup:get_random_pid(),
    gen_server:call(Pid, {list, Bucket, Options }).
list_objects (Bucket) ->
    list_objects( Bucket, [] ).
    
    
stop(_State) ->
    ok.
 
get(Atom, Env)->
    case application:get_env(Atom) of
     {ok, Value} ->
         Value;
     undefined ->
         case os:getenv(Env) of
      false ->
      error;
      Value ->
      Value
         end
    end.
    
param(Name, Default)->
case application:get_env(?MODULE, Name) of
{ok, Value} -> Value;
_-> Default
end.
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server