Dynamically setting parameters for S3-like post

83 views
Skip to first unread message

Daniel

unread,
Mar 17, 2012, 7:01:30 PM3/17/12
to Omeka Dev
I am working on a plugin that calls an HTTP POST to store items in the
Internet Archive's S3-like system whenever the item is saved.

I could hack a POST that using the plugin hooks, but I would rather
use the methods already built into the Zend framework by modifying
this Omeka adaptor:

Omeka_Storage_Adapter_ZendS3

Unfortunately, key parameters for the POST are defined in the
config.ini file:

; Sample S3 cloud storage configuration
;
; The accessKeyId, secretAccessKey, and bucket options are all
required.
; If the expiration option is set, files will be uploaded with
"private"
; access, and Omeka will generate URLs that are only valid for a
limited
; time. If the expiration option is missing or left commented out,
; uploaded files will always be publicly readable.
;
; storage.adapter = "Omeka_Storage_Adapter_ZendS3"
; storage.adapterOptions.accessKeyId =
; storage.adapterOptions.secretAccessKey =
; storage.adapterOptions.bucket =
; storage.adapterOptions.expiration = 10 ; URL expiration time (in
minutes)

Is there any way a plugin could modify these parameters on a running
instance of Omeka? I would like to use the robust built-in code, but
buckets change with items, and I would rather not ask users of the
plugin to directly modify a scary config.ini file.

John Flatness

unread,
Mar 19, 2012, 11:07:01 AM3/19/12
to omek...@googlegroups.com
Those `adapterOptions` INI settings simply get thrown into an array
that's passed to the storage adapter's constructor.

So, you can create a new Omeka_Storage_Adapter_ZendS3 object yourself in
code, set whatever parameters you want, and set that as the current
adapter with Omeka_Storage's setAdapter().

In short, you don't need to edit the INI file if you don't want to.

Daniel Vizzini

unread,
Mar 19, 2012, 11:39:21 AM3/19/12
to omek...@googlegroups.com
John,

Thank you for the reply.

I have tried a different tactic. I do not know if the native Zend/Omeka support can make a file that has already been uploaded to an Omeka DB to transfer. Instead I am using PHP's cURL object to upload to the S3-like API (http://www.archive.org/help/abouts3.txt).

My header array looks like this:

$header = array()
array_push($header, 'x-amz-auto-make-bucket:1'); 
array_push($header, 'x-archive-queue-derive:1');
array_push($header, 'authorization: LOW '.get_option('access_key').':'.get_option('secret_key'));
array_push($headerForPut, 'content-type: '.$fileToBePut->getMimeType());
array_push($headerForPut, 'content-length: '.$fileToBePut->size);

My cURL object could be configured like htis:

curl_setopt($cURL, CURLINFO_CONTENT_LENGTH_UPLOAD, $fileToBePut->size);
curl_setopt($cURL, CURLOPT_READFUNCTION, array(&$this, 'stream_function'));
curl_setopt($cURL, CURLOPT_UPLOAD, 1);

with stream_function being described as follows:

function stream_function($handle, $fd, $length)
{
return fread(fopen($file_uri,'r'), $length);
}

Or like this:

curl_setopt($cURL, CURLOPT_PUT, 1);
curl_setopt($cURL, CURLOPT_INFILE,  fopen($file_uri,'r'));
curl_setopt($cURL, CURLOPT_INFILESIZE, $fileToBePut->size);

Neither seem to work. I get a 411 or 400 response.

I was now wondering if what I am trying to do is possible at all, or would be possible with big files. Could a browser handle downloading a 2GB off one site and then uploading it to another? Should I design this plugin to only upload files that are available locally? 

Thank you.

-Daniel Vizzini

--
You received this message because you are subscribed to the Google Groups "Omeka Dev" group.
To post to this group, send email to omek...@googlegroups.com.
To unsubscribe from this group, send email to omeka-dev+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/omeka-dev?hl=en.


Daniel Vizzini

unread,
Mar 19, 2012, 11:53:43 AM3/19/12
to omek...@googlegroups.com
I am designing this all for a plug-in, by the way, in the after_save_item hook. 
Message has been deleted
Message has been deleted

John Flatness

unread,
Mar 19, 2012, 3:53:35 PM3/19/12
to omek...@googlegroups.com
If you're not trying to upload files that are attached to Omeka items,
and you don't want to use the user's authentication info that's in the
INI file, there's really no point in using the Omeka_Storage system.

If you just want to use the S3 API, it'd be better to use the Zend
Framework component Zend_Service_Amazon_S3.

-John

On 03/19/2012 02:37 PM, Daniel wrote:
> Sorry, can I use the built-in S3 class transfer a file from the Omeka
> server
> to an S3-like API? I may have just not entered the right headers.
>
> On Mar 19, 11:34 am, Daniel Vizzini<dvizz...@gmail.com> wrote:
>> Also, I tried constructing an Omeka_Storage_Adapter_ZendS3 instance as follows:
>>
>> $adaptor->move(file_download_uri($file), 'http://s3.us.archive.org/'.'ks_beam_me_up_test_bucket_three');
>>
>> where I defined the error as follows:
>>
>> $adaptor = new Omeka_Storage_Adapter_ZendS3(array(Omeka_Storage_Adapter_ZendS3::AWS_KEY_OP TION
>> => get_option('access_key'),
>> Omeka_Storage_Adapter_ZendS3::AWS_SECRET_KEY_OPTION =>
>> get_option('secret_key'),Omeka_Storage_Adapter_ZendS3::BUCKET_OPTION
>> => 'ks_beam_me_up_test_bucket_three'));
>>
>> I got the following error;
>>
>> Omeka_Storage_Exception: Unable to move file
>>
>> Can I use the built-in S3 class transfer a file from the Omeka server
>> to an S3-like header? I may have just not entered the right headers.


>>
>>
>>
>>
>>
>>
>>
>> On Mon, Mar 19, 2012 at 8:53 AM, Daniel Vizzini<dvizz...@gmail.com> wrote:
>>
>>> I am designing this all for a plug-in, by the way, in the after_save_item hook.
>>

>>>>> To unsubscribe from this group, send email to omeka-dev+...@googlegroups.com.

Daniel Vizzini

unread,
Mar 19, 2012, 4:01:01 PM3/19/12
to omek...@googlegroups.com
These files are associated with an Omeka item. They are meant to be
pushed to the Internet Archive in an after_save_item hook. Right now
I am trying to access them through the file_download_uri() function.
Is there a better way?
Reply all
Reply to author
Forward
Message has been deleted
0 new messages