顯示具有 google storage 標籤的文章。 顯示所有文章
顯示具有 google storage 標籤的文章。 顯示所有文章

2010年7月22日 星期四

[Note] Google Storage API 開發二三事

Google Storage API
GS 提供了RESTful的介面供開發者使用

GET Service—lists all of the buckets that you own.
PUT Bucket—creates a bucket and changes the permissions on a bucket.
GET Bucket—lists the contents of a bucket or retrieves the ACLs that are applied to a bucket.
DELETE Bucket—deletes an empty bucket.
GET Object—downloads an object or retrieves the ACLs that are applied to an object.
PUT Object—uploads an object or applies new ACLs to an object.
DELETE Object—deletes an object.
HEAD Object—lists the metadata for an object.
POST Object—uploads an object by using HTML forms.

而目前網路上提供的資源如下:

Boto: Python interface to GS and S3
CloudBerry: Windows的檔案管理工具
Cyberduck : Mac上的browser
Dasein Cloud: open source Java API(如JDBC)
Data Nucleus : JDO/JPA plug in
Gladinet: maps network drives and provides AFS suppor
gstorea :Ruby client library
SharpGsa C# library

時間格式的要求上 google storage API要求的時間格式為UTC,時間格式處理如下:

SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ssz", new Locale("US"));
Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));

format.setCalendar(cal);
return format.format(new Date());


而Google Storage在每個request都需使用auth
Signature = Base64-Encoding-Of(HMAC-SHA1(UTF-8-Encoding-Of(YourGoogleStorageSecretKey, MessageToBeSigned)))

public static String makeHMACSHA(String msg) {
byte[] hmac = new byte[msg.length()];
SecureRandom sr = new SecureRandom();
byte[] keyBytes = new byte[20];
sr.nextBytes(keyBytes);

try {
//將google提供的Secret key以UTF-8的編碼取出
SecretKey sk = new SecretKeySpec(GS_SK.getBytes("utf-8"),
"HmacSHA1");
//使用HMAC-SHA1
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(sk);
//傳入UTF-8編碼的訊息
mac.update(msg.getBytes("utf-8"));
hmac = mac.doFinal();

} catch (Exception e) {
e.printStackTrace();
} finally {
//回傳Base64編碼過得HMAC-SHA1值
return new String(Base64.encodeBase64(hmac));

}

}

2010年6月8日 星期二

Google Storage 開箱文

2010 5/19-20的Google I/O 2010除了最紅的Android Froyo與Google TV外,也介紹了Google Storage服務,首階段開放給現場參予的developer,在同事的提醒下填寫了申請信,也就先暫時結案了,直到了今天打開信箱


意外的發現了google竟然回覆給我並批准了我的申請(!!!!)

Google Storage目前提供了一個web介面供建立 Bucket,需注意的是Bucket 的命名空間是全球user共用的,所以一開始沒發現時以為自己為啥沒辦法建立music資料夾(-_-|||)
建立完bucket之後還可新增資料夾及設定權限

設定分享權限後可得到link位置 如(http://commondatastorage.googleapis.com/celtics/celt.jpg)
可供網路檔案hosting用,如下圖

而開發者可透過GSUtil Tool以command line方式對bucket進行一些操作,而計費方式大概就依照storage, bandwidth與request來收費

有更多的心得會再補上