May 31, 2011

Delphi REST Clients Repository Opening With Amazon S3

Today, I'm officially opening my "Delphi REST Clients" SVN repository (hosted on code.marcocantu.com) with a rather complete class for working with Amazon S3, Simple Storage Service.

Today, I'm officially opening my "Delphi REST Clients" SVN repository (hosted on code.marcocantu.com) at http://code.marcocantu.com/p/delphirestclients/

The subversion command to get the entire repository (currently quite limited) is:

      svn co -r HEAD http://code.marcocantu.com/svn/marcocantu/delphirestclients
    

My intension is to use this repository for hosting all of the various REST client classes and demos Ive' written over the last few years. Contributions by other developers are welcome. 

Amazon S3

As a starting point, I'm finally making available the soruce code of my class for working with Amazon S3, Simple Storage Service. I had introduced this Amazon S3 class at the last CodeRage, and covered it in a past article of http://www.blaisepascal.eu/. Now I've written a new article, which will become available soon and coverign this extended version of the demo. I think this is a relevant example, as the only freely available Delphi code for Amazon S3 was a very old demo by Tim Anderson, at http://www.itwriting.com/blog/23-amazon-s3-delphi-sample.html. There is also some interesting ocde (different from mine) by Chilkat at http://www.example-code.com/delphi/s3_hmac_sha1.asp.

My project is based on a support class / component including a generic implementation of the secutiry algorithm required by S3 () and offering the following ready-to-use methods:

 

    // global operations
    function ListBuckets: TArray <TBucketInfo>;

    // buckest operations
    procedure CreateBucket (const bucketName: string);
    procedure DeleteBucket (const bucketName: string);
    function BucketContent (const bucketName: string): TArray <TObjectInfo>;

    // objects operations
    procedure UploadObject (const BucketName, Name, FileName, ContentType: string);
    procedure DownloadObject (const BucketName, Name: string; aStream: TStream);
    procedure DeleteObject (const BucketName, Name: string);

 

I might improve the code making actual calls indie threads, while now they use Indy directly and so they are blocking. This is not the complete intereface of S3, as it misses authorization requests and other settings, but it is certainly quite a good start. You can use it for listing folders, getting the contents of each, create and delete folders, upload and download files.

Note: You need to have an amazon.ini file in your documents folder with your access key and secret access key to use this project.

For more information refer to the article... or some future book of mine. Below is main form of the project, I plan showing this demo with a video ASAP (most showing how to use it, than how it works internally).

 

 





 

16 Comments

Delphi REST Clients Repository Opening With Amazon S3 

 Wow!!

Great work Marco.

This is just what we need.

I don't know if I'm good enough to contribute to the 
project, but if I am, I will.

I hope you present this at DelphiLive.

Thanks,

Keith
Comment by Keith on May 31, 23:47

Delphi REST Clients Repository Opening With Amazon S3 

Keith, thanks for the feedback. Use it, find any bug, 
try calling extra APIs not supported... anything helps 
the project.

As the Delphi Live I won't be there. I don't speak at 
conferences for which I have to pay my own flight and 
expenses (and also I'm not sure I'd be welcomed at this 
conference).

Come to the next year Delphi Developer Days in US and 
I'll have a session on REST clients <g>.
Comment by Marco Cantu [http://www.marcocantu.com] on June 1, 07:36

Delphi REST Clients Repository Opening With Amazon S3 

Marco,
A good endeavor from your side! I know you have some 
arguments against the SOAP and in favor of REST. Do you 
plan any examples of SOAP servers and clients?
Thank you!
Comment by IL [] on June 2, 21:23

Delphi REST Clients Repository Opening With Amazon S3 

The goal is to focus on REST clients. Most of the public 
services I use (for example Google ones) don't even have 
a SOAP interface. And Delphi support for SOAP is not 
always impeccable... mostly because there are variations 
on SOAP.
Comment by Marco Cantu [http://www.marcocantu.com] on June 2, 21:26

Delphi REST Clients Repository Opening With Amazon S3 

Good morning!   I am trying to get this to work using D7 and Indy 10 and 
I keep getting a TCP error 10053 when I try to put an object.  Oddly, the 
download works fine.  Same access key, etc.  Any thoughts?  Thank you! 
Comment by Malcolm on July 11, 13:08

Delphi REST Clients Repository Opening With Amazon S3 

Do you have this client for Delphi 2007?
Comment by Aleksey on July 22, 12:21

Delphi REST Clients Repository Opening With Amazon S3 

I have been able to rewrite your code for Delphi 2007
but i don't know how to Delete object. TIDHTTP doesn't
have Delete in D 2007. Can somebody help me?
Comment by Aleksey on July 25, 09:08

Delphi REST Clients Repository Opening With Amazon S3 

Very good example, got it working right away in Delphi 
2010. But I'm struggling with one thing: I would like to  
upload files and set the acl to public-read, so images 
can be downloaded using an URL. I've been messing around 
with both strCanonicalizedAmzHeaders and 
strCanonicalizedResource, but can not get it working. 
Could anybody be so kind to help me out with this?
Comment by Herman van der Hoek on August 29, 11:34

Delphi REST Clients Repository Opening With Amazon S3 

 If you change TimeZone and Local Date and Time on your 
computer, client will not work. How can I solve this 
problem?
Comment by Dag on November 30, 16:05

Delphi REST Clients Repository Opening With Amazon S3 

Hello,

i have a question about upload files.. the only way 
to upload a file into amazon s3 is via PUT function?

POST function is supported? 

the problem with fIdHttp.Put is that i cant control 
with progress bar the upload ... the OnWorkEnd 
function is fired when the PC has sent all stream to 
router not the effective end of transaction on Amazon

many thanks

Comment by marco boglione on January 7, 10:54

Delphi REST Clients Repository Opening With Amazon S3 

Hi,

How do I download the code for this please ?

Each time I try, I get a login prompt for the SVN but
I do not know the details. 
Comment by Anthoni Gardner [http://www.evanine.net] on July 29, 15:41

Delphi REST Clients Repository Opening With Amazon S3 

While issuing the following command, I am prompted for 
username and password.  What should I add?

svn co -r HEAD 
http://code.marcocantu.com/svn/marcocantu/delphirestcli
ents

Thanks.
Comment by [http://blog.marcocantu.com/blog/delphi_rest_client_repository_opening.html] on February 1, 00:17

Delphi REST Clients Repository Opening With Amazon S3 

 The correct link is:

http://code.marcocantu.com/svn_public/marcocantu_delphirestclients

(since the repository was moved). Link in signature.
Comment by Marco Cantu [http://code.marcocantu.com/svn_public/marcocantu_delphirestclients] on February 1, 11:21

Delphi REST Clients Repository Opening With Amazon S3 

Hello Marco.

Could you show how to create a folder/object 
programmatically?  Is there a sample project that can 
be studied?

Thanks.
Comment by [http://blog.marcocantu.com/blog/delphi_rest_client_repository_opening.html] on March 8, 20:23

Delphi REST Clients Repository Opening With Amazon S3 

 Boa Tarde Marco,

O link do repositório
"http://code.marcocantu.com/p/delphirestclients/" está
quebrado poderia me fornecer o novo link , ou enviar
por email?

Atenciosamente

Paulo Marques
marques@teleportweb.com.br
Comment by Paulo Marques on June 4, 17:46

Delphi REST Clients Repository Opening With Amazon S3 

The repository was moved. Still at http://code.marcocantu.com, 
but the internal links to individual projects have changed.
Comment by Marco Cantu [http://code.marcocantu.com] on June 7, 16:48


Post Your Comment

Click here for posting your feedback to this blog.

There are currently 0 pending (unapproved) messages.