javascript

S3Ajax: creating buckets and uploading keys

Continuing on Mashup Guide :: listing keys with S3Ajax, here I present a Chickenfoot script to create a bucket and upload a file (specifically, it creates a bucket by the name of raymondyeetest and uploads a file (D:\Document\PersonalInfoRemixBook\examples\ch16\Exported Items.rdf from my WinXP machine) to the key exportitems.rdf in the bucket:

include("D:\\document\\JavaScriptLib\\sha1.js");
include("D:\\document\\JavaScriptLib\\S3Ajax.js");

var AWSAccessKeyId = "[AWSAccessKeyId]";
var AWSSecretAccessKey = "[AWSSecretAccessKey]";

S3Ajax.URL = 'http://s3.amazonaws.com';
S3Ajax.DEBUG = true;
S3Ajax.KEY_ID = AWSAccessKeyId;
S3Ajax.SECRET_KEY = AWSSecretAccessKey;

// function to read contents from a file

function read_file_contents(aFileURL) {
  // https://developer.mozilla.org/en/Code_snippets/File_I%2f%2fO#Binary_File

  var ios = Components.classes["@mozilla.org/network/io-service;1"]
                      .getService(Components.interfaces.nsIIOService);
  var url = ios.newURI(aFileURL, null, null);

  if (!url || !url.schemeIs("file")) throw "Expected a file URL.";
  var bFile = url.QueryInterface(Components.interfaces.nsIFileURL).file;
  var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
                          .createInstance(Components.interfaces.nsIFileInputStream);
  istream.init(bFile, -1, -1, false);
  var bstream = Components.classes["@mozilla.org/binaryinputstream;1"]
                          .createInstance(Components.interfaces.nsIBinaryInputStream);
  bstream.setInputStream(istream);
  var bytes = bstream.readBytes(bstream.available());
  return bytes;

}

// create a bucket

var newBucketName = 'raymondyeetest';

S3Ajax.createBucket(newBucketName, function() {
    output("created a buicket: " + newBucketName);
    s3_list();
}, function () {
      output ("error in createBucket");
   }
);

// add a key to a bucket

var fileURL = 'file:///D:/Document/PersonalInfoRemixBook/examples/ch16/Exported%20Items.rdf'
var content = read_file_contents(fileURL);
alert(content);

S3Ajax.put(newBucketName , "exportitems.rdf", content,
    {
       content_type: "application/xml; charset=UTF-8",
       meta:  {'creator':'Raymond Yee'},
       acl:    "public-read",
    },
    function(req) {
        output("Upload succeeded");
    },
    function(req, obj) {
        output("Upload failed");
    }
);

A few things to note about this code:

  • read_file_contents() doesn't strike me as a terribly elegant way of reading contents from a file -- but that's what I have working for now
  • a tricky part of getting this to work was to note that in FF 3.x,  charset=UTF-8 is automatically tacked on to content-type HTTP request header in a xmlhttprequest -- I don't know how to change the charset or whether you can -- and why UTF-8 is being tacked on.  But figuring out the charset was crucial to getting this working since the content-type HTTP header is used in the calculation of the Amazon S3 signature.

AJAX
Amazon S3
chickenfoot
javascript

Comments (0)

Permalink

listing keys with S3Ajax

In a previous post (learning how to use S3Ajax to access Amazon S3), I show how to use Chickenfoot and S3Ajax to list S3 buckets. Here is a slight elaboration of the code to list the keys within buckets (in addition to the buckets):

include("D:\\document\\JavaScriptLib\\sha1.js");
include("D:\\document\\JavaScriptLib\\S3Ajax.js");

var AWSAccessKeyId = "[AWSAccessKeyId]";
var AWSSecretAccessKey = "[AWSSecretAccessKey]";

S3Ajax.DEBUG = true;
S3Ajax.KEY_ID = AWSAccessKeyId;
S3Ajax.SECRET_KEY = AWSSecretAccessKey;

function s3_listKeys(bucket) {
  S3Ajax.listKeys(bucket,null,
    function(req, obj) {
        var contents = obj.ListBucketResult.Contents;
        for (var i=0, item; item=contents[i]; i++) {
           output("key: " + bucket + ": " + item.Key +
            " [" + item.LastModified + '] ' +
             " (" + item.Size + ")");
        }
    },
     function(req,obj) {
        output("s3_listKeys failed at " + (new Date()));
     }
  )
} // s3_listKeys

S3Ajax.listBuckets(
    function(req, obj) {
        if (obj.ListAllMyBucketsResult) {
            var buckets = obj.ListAllMyBucketsResult.Buckets.Bucket;
            for (var i=0, bucket; bucket=buckets[i]; i++) {
              output (
                    "bucket: " + bucket.Name + ' ['+
                      bucket.CreationDate+']'
              );
              s3_listKeys(bucket.Name);
            }
        }
    },
    function(req) {
        output ("Buckets list failed at "+(new Date()));
    }
);

Amazon S3
chickenfoot
javascript

Comments (1)

Permalink

Chapter 8 on the programmable web browser, Javascript, and AJAX

Starting today, I will be writing much more often on this weblog to narrate the progress of my mashup book. The writing has been going well, but needless to say, there's so much more to do. This week, I am working on two fronts: cleaning up Chapter 1, an overview of mashups, and drafting, Chapter 8 on the programmable Web browser, Javascript, and AJAX. Although I am writing many, many words in a word processor -- many of which I hope will make it into the final draft of my book, I long to write shorter pieces, which will facilitate the development of the book. That's why am I'm taking time out of the book to weblog a bit.

Let me tell you a bit about Chapter 8, whose working title is "Learning Ajax/JavaScript widgets and their APIs." In thinking about the chapter today, I realize that the big idea I want to get at is that the modern web browser is programmable and hence, is a rich platform for mashing up data and services. As a connoisseur of mashups, I would want to figure out all the different ways in which I could extend, change, subvert, and customize the web browser, which is the dominant client-side platform for exchanging information on the Internet. The possibilities are astounding for customization both in how a web server host communicates with others and how you as an end-user could process communications coming at you.

A specific example, and certainly not a surprising one, to cover in Chapter 8 is Google Maps, which I call (without great precision of wording) an Ajax widget. Ajax, because it involves the constant and fluid interchange of data between the browser and the server executed through JavaScript -- and a widget because one can use Google maps without knowing all the inner workings of Ajax. That is, you can use it at a high level of abstraction. (I do use Google maps as a specific instance of Ajax widgets but I cover Google maps again in greater detail in other chapters to emphasize the mapping (functional) aspect of it -- instead of the technical implementation part of it.)

Ajax is a rich subject, as can be seen in by the myriad books that have been published recently on the subject. I would like to put Ajax in the larger context of the programmable Web browser. Here I will admit to struggling with how to piece together a chapter that I believe should at least mention, if not plumb the depths of the following:

  • both how an "ideal" W3C DOM-standards compliant browser works and how various browsers actually work in various areas: how javascript is implemented, object models behavior, CSS, events, etc.
  • Javascript-based APIs, widgets such as Google maps -- what are they, how to use any all.
  • non-browser environments for Javascript, such as Google Gadgets, Yahoo Widgets, Adobe Acrobat
  • extension mechanisms in browsers (Firefox addons, Safari , IE , Opera)
  • Javascript and browser debugging tools like Firebug
  • Javascript libraries: how they relate and what can be intermixed -- and which ones are tied to which web programming frameworks.
  • what people have done already on all these fronts using Javascript and remixing the browser
  • how to write Javascript and Javascript widgets that can be reused by other people, including cross-platform Javascript
  • ideas of what you can do in terms of mashups

I obviously would not be to cover all these topics, nor should I even try! What I plan to actually cover as a way into this big list of topics is the following:

  • the lastest versions of Firefox, instead of looking in depth at all browers -- old and new
  • the Yahoo UI Library, as a specific example of a packaged javascript library
  • a walk-through of how to use Firefox + Firebug / Javascript Shell + YUI Connection Manager
  • to build a Google Map example, as a way to get into Ajax widgets in general
  • how to build a basic AJAX call to Flickr
  • how to write a simple Greasemonkey script to lay the foundation of understanding Google Maps in Flickr , a major example in the book).

AJAX
Chapter 08
javascript
Meta
web browser
web services

Comments (0)

Permalink

lasix surgery savannah ga 3 Month Prescription Accutane Low Dose accutane timeline; symptoms of zoloft working Buy Levitra Online lipitor drug cost! prednisone stopped taking side effects Side Effects From Zoloft difference between lexapro and celexa accutane timeline; What Will Cipro Treat symptoms of zoloft working lipitor drug cost! Accutane Dosage prednisone stopped taking side effects difference between lexapro and celexa Prednisone Side Effects Skin accutane timeline; symptoms of zoloft working Prednisone Dose Pack lipitor drug cost! lipitor is there a generic Zoloft And Alcohol difference between lexapro and celexa accutane timeline; Prednisone Side Effect symptoms of zoloft working lipitor drug cost! Zithromax Antibiotics Online prednisone stopped taking side effects difference between lexapro and celexa Side Effects Lexapro accutane timeline; symptoms of zoloft working Pill Propecia lipitor drug cost! prednisone stopped taking side effects Nexium Overdose difference between lexapro and celexa accutane timeline; Prednisone And Withdrawal Symptoms symptoms of zoloft working lipitor drug cost! Cheapest Generic Levitra

prednisone stopped taking side effects

Cough and wheezing with lipitor high dose prednisone and pcp prophylaxis 366. Withdrawals From Lexapro accutane timeline; symptoms of zoloft working Cat On Prozac lipitor drug cost! prednisone stopped taking side effects Lexapro Side Affects difference between lexapro and celexa accutane timeline; Effects Of Zoloft symptoms of zoloft working get a prescription for propecia Dangers Of Prozac prednisone stopped taking side effects difference between lexapro and celexa Medicine Side Effects Lipitor accutane timeline; symptoms of zoloft working Substitutes For Lasix lipitor drug cost! lipitor is there a generic Connection Between Zoloft And Hair Loss difference between lexapro and celexa accutane timeline; Cough And Wheezing With Lipitor symptoms of zoloft working lipitor drug cost! Lexapro Cost prednisone stopped taking side effects difference between lexapro and celexa Side Effects Of The Drug Lexapro accutane timeline; symptoms of zoloft working Losing Weight After Stopping Lexapro lipitor drug cost! prednisone stopped taking side effects Accutane Attorneys Southern California difference between lexapro and celexa accutane timeline; Zithromax Dosage symptoms of zoloft working lipitor drug cost! Advertising Campaign Propecia prednisone stopped taking side effects difference between lexapro and celexa Lasix Interlase accutane timeline; symptoms of zoloft working Accutane Buy Online Cheaper lipitor drug cost! prednisone stopped taking side effects Can Zoloft Cause Hair Loss difference between lexapro and celexa accutane timeline; Viagra Cialis Levitra symptoms of zoloft working cipro and std treatment Lipitor 20 Mg prednisone stopped taking side effects difference between lexapro and celexa Side Effects Of Cipro accutane timeline; symptoms of zoloft working Zoloft Side Affects lipitor drug cost! prednisone stopped taking side effects Wellbutrin And Prozac difference between lexapro and celexa accutane timeline; Time For Nexium To Work symptoms of zoloft working lipitor drug cost! Prednisone

prednisone stopped taking side effects

Cough and wheezing with lipitor high dose prednisone and pcp prophylaxis 366. Zoloft Withdrawl accutane timeline; symptoms of zoloft working Long Term Prednisone Use lipitor drug cost! lipitor is there a generic Accutane Attorney Ohio difference between lexapro and celexa accutane timeline; Nexium Acid Reflux symptoms of zoloft working lipitor drug cost! Alcohol And Zoloft prednisone stopped taking side effects difference between lexapro and celexa Cipro 500mg accutane timeline; symptoms of zoloft working Over The Counter Form Of Zithromax lipitor drug cost! prednisone stopped taking side effects
Robitussin And Clomid
difference between lexapro and celexa clomid with triplets Clomid Ovulation symptoms of zoloft working lipitor drug cost!

Twins On 50 Mg Clomid

prednisone stopped taking side effects Cough and wheezing with lipitor high dose prednisone and pcp prophylaxis 366. Prednisone Natural Substitute Moonface accutane timeline; symptoms of zoloft working Cheap Levitra lipitor drug cost! lipitor is there a generic Accutane Acne Medication difference between lexapro and celexa accutane timeline; Lipitor Side Effects Liver symptoms of zoloft working lipitor drug cost! Cost Of Clomid prednisone stopped taking side effects difference between lexapro and celexa Weight Loss With Zoloft accutane timeline; symptoms of zoloft working Nolvadex Online lipitor drug cost! prednisone stopped taking side effects Cipro Antibotic difference between lexapro and celexa accutane timeline; Food Affect Nexium symptoms of zoloft working lipitor drug cost! Renogram With Lasix prednisone stopped taking side effects difference between lexapro and celexa Nexium Rebate
accutane timeline;
clomid dosage lutenizing hormone short Vet Dog Care Lasix Medication lipitor drug cost! prednisone stopped taking side effects Ultracet No Prescription difference between lexapro and celexa accutane timeline; Clomid Miscarriages symptoms of zoloft working lipitor drug cost! Lipitor And Als prednisone stopped taking side effects difference between lexapro and celexa Zoloft Zoloft accutane timeline; symptoms of zoloft working Prednisone And Alcohol lipitor drug cost!
prednisone stopped taking side effects
Genuine Levitra No Prescription difference between lexapro and celexa clomid with triplets Prednisone Induced Diabetes symptoms of zoloft working lipitor drug cost!

Nexium Calcium

prednisone stopped taking side effects Cough and wheezing with lipitor high dose prednisone and pcp prophylaxis 366. Accutane Dry Skin Moisturizer accutane timeline; symptoms of zoloft working Performance Enhancement Prednisone lipitor drug cost! lipitor is there a generic Zoloft Bone Loss difference between lexapro and celexa accutane timeline; Buy Cipro No Prescription symptoms of zoloft working lipitor drug cost! Lasix California prednisone stopped taking side effects difference between lexapro and celexa Lexapro Diabetes accutane timeline; symptoms of zoloft working Class Action Lawsuit On Prednisone lipitor drug cost! prednisone stopped taking side effects Baldness Due To Lipitor difference between lexapro and celexa accutane timeline; Withdrawing From Prednisone symptoms of zoloft working lipitor drug cost! Articles On Prozac prednisone stopped taking side effects difference between lexapro and celexa Prednisone Side Affects accutane timeline; symptoms of zoloft working Prednisone Frequent Urination lipitor drug cost! lipitor is there a generic Does Ultracet Work difference between lexapro and celexa accutane timeline; Zoloft And Breastfeeding symptoms of zoloft working get a prescription for propecia

Effexor Lexapro Taken Together

prednisone stopped taking side effects Cough and wheezing with lipitor high dose prednisone and pcp prophylaxis 366. Prednisone And Dogs accutane timeline; symptoms of zoloft working Prednisone Dosing lipitor drug cost! prednisone stopped taking side effects Prednisone Withdrawal difference between lexapro and celexa accutane timeline; Cipro Xr Calcium Carbonate Chelating Agent symptoms of zoloft working lipitor drug cost! Discount Levitra Online prednisone stopped taking side effects difference between lexapro and celexa Zoloft For Headaches accutane timeline; symptoms of zoloft working Lipitor Flatulence lipitor drug cost! prednisone stopped taking side effects Lexapro Drug Interactions difference between lexapro and celexa accutane timeline; Prednisone Dosepak symptoms of zoloft working lipitor drug cost! Abruptly Stopping Zoloft

prednisone stopped taking side effects

Cough and wheezing with lipitor high dose prednisone and pcp prophylaxis 366. Too High Zoloft Dosage accutane timeline; symptoms of zoloft working Cheap Prednisone lipitor drug cost! prednisone stopped taking side effects Accutane Neck Pain Back Head difference between lexapro and celexa accutane timeline; Cipro Xr 1000mg symptoms of zoloft working

lipitor drug cost!

Buying Clomid Online prednisone stopped taking side effects
Cough and wheezing with lipitor high dose prednisone and pcp prophylaxis 366.
Sexual Side Effect Of Zoloft accutane timeline; clomid dosage lutenizing hormone short Cost Of Zoloft lipitor drug cost! prednisone stopped taking side effects Zoloft Withdrawals Leg Pain difference between lexapro and celexa accutane timeline; Weight Loss While On Lexapro symptoms of zoloft working lipitor drug cost! Lexapro Vs Cymbalta prednisone stopped taking side effects difference between lexapro and celexa Levitra Online accutane timeline; symptoms of zoloft working Online Drug Purchase Levitra lipitor drug cost! prednisone stopped taking side effects Prednisone Withdrawals difference between lexapro and celexa accutane timeline; Levitra Medication symptoms of zoloft working lipitor drug cost! Lexapro Dosage prednisone stopped taking side effects difference between lexapro and celexa Long Term Effects Of Prednisone accutane timeline; symptoms of zoloft working Buy Prozac Online lipitor drug cost! prednisone stopped taking side effects Zoloft And Side Effects difference between lexapro and celexa accutane timeline; Prednisone Effects On Blood symptoms of zoloft working lipitor drug cost!

Accutane Online

prednisone stopped taking side effects Cough and wheezing with lipitor high dose prednisone and pcp prophylaxis 366. Sabatino Cipro accutane timeline; symptoms of zoloft working Clomid Twins lipitor drug cost! lipitor is there a generic Generic Forms Of Prozac difference between lexapro and celexa accutane timeline; Zoloft Elevated Lfts symptoms of zoloft working lipitor drug cost! Cytotec Without A Prescription prednisone stopped taking side effects difference between lexapro and celexa
What Is Prozac
accutane timeline; clomid dosage lutenizing hormone short Accutane 4 Mg lipitor drug cost!
prednisone stopped taking side effects
Zithromax American Made difference between lexapro and celexa clomid with triplets Side Effects Propecia symptoms of zoloft working lipitor drug cost! Hyponatremia Nexium prednisone stopped taking side effects difference between lexapro and celexa Atlanta Accutane Side Effects accutane timeline; symptoms of zoloft working Medicine Lexapro lipitor drug cost!
prednisone stopped taking side effects
Cheap Propecia difference between lexapro and celexa clomid with triplets Can You Take Zoloft While Pregnant symptoms of zoloft working lipitor drug cost!

Ultracet

prednisone stopped taking side effects

medicine side effects lipitor
Zoloft Wellbutrin accutane timeline; clomid dosage lutenizing hormone short Defferance Betweek Zocor And Lipitor lipitor drug cost! prednisone stopped taking side effects Rogaine Scalp Med Propecia Minoxidil difference between lexapro and celexa accutane timeline; Zithromax Rash symptoms of zoloft working lipitor drug cost! Buy Prednisone prednisone stopped taking side effects difference between lexapro and celexa Is Lexapro Simular To Xanax accutane timeline; symptoms of zoloft working Accutane Lawyers Los Angeles lipitor drug cost! prednisone stopped taking side effects Cipro Neurological Side Effects difference between lexapro and celexa accutane timeline; Lexapro Patient Experiences symptoms of zoloft working lipitor drug cost! Lipitor Problems prednisone stopped taking side effects difference between lexapro and celexa Prednisone Dosage For Cats accutane timeline; symptoms of zoloft working Pregnancy And Zoloft lipitor drug cost! lipitor is there a generic Accutane For Acne difference between lexapro and celexa accutane timeline; Twins Clomid symptoms of zoloft working lipitor drug cost! Clomid For Testosterone Replacement prednisone stopped taking side effects difference between lexapro and celexa Prednisone For Lymphoma accutane timeline; symptoms of zoloft working Prednisone For Canine Lymphoma lipitor drug cost! prednisone stopped taking side effects Lipitor And Alcohol difference between lexapro and celexa accutane timeline; Lexapro Withdrawl Symptom symptoms of zoloft working

lipitor drug cost!

Clomid And Iui prednisone stopped taking side effects Cough and wheezing with lipitor high dose prednisone and pcp prophylaxis 366. Buspar Zoloft accutane timeline; symptoms of zoloft working Cytotec Safe For Abortion lipitor drug cost! lipitor is there a generic Accutane Statistics difference between lexapro and celexa accutane timeline; Lexapro Medicine symptoms of zoloft working get a prescription for propecia Shelf Life Of Prednisone prednisone stopped taking side effects difference between lexapro and celexa Lexapro 20mg accutane timeline; symptoms of zoloft working Cheap Lexapro lipitor drug cost! prednisone stopped taking side effects Lipitor Lawsuit difference between lexapro and celexa accutane timeline; Rimonabant Side Effects symptoms of zoloft working lipitor drug cost!

Buy Generic Propecia Online

prednisone stopped taking side effects Cough and wheezing with lipitor high dose prednisone and pcp prophylaxis 366. Buy Zoloft Online accutane timeline; symptoms of zoloft working Clomid Day 3 Vs Day 5 lipitor drug cost! prednisone stopped taking side effects Lexapro Abuse difference between lexapro and celexa accutane timeline; Lipitor Unusual Side Effect symptoms of zoloft working cipro and std treatment Nexium Rebates prednisone stopped taking side effects difference between lexapro and celexa Menstruation And Zoloft accutane timeline; symptoms of zoloft working Accutane Side Effects lipitor drug cost! lipitor is there a generic Nolvadex Doctors Testosterone Gel difference between lexapro and celexa accutane timeline; Buy Accutane Online symptoms of zoloft working lipitor drug cost! 13 Dpo Clomid prednisone stopped taking side effects difference between lexapro and celexa Prednisone Rx accutane timeline; symptoms of zoloft working Started Zoloft And Ativan Today lipitor drug cost! lipitor is there a generic Zoloft Dosage difference between lexapro and celexa accutane timeline; Long Term Use Of Prednisone symptoms of zoloft working cipro and std treatment Weight Loss After Zoloft prednisone stopped taking side effects difference between lexapro and celexa Get High Off Zoloft accutane timeline; symptoms of zoloft working Lexapro And Pregnancy
lipitor drug cost!
Lexapro anti depressant manufacturer prednisone ingredients 324. Buy Cheap Amoxil Without Prescription difference between lexapro and celexa accutane timeline; Does Prozac Make You Lose Weight symptoms of zoloft working cipro and std treatment Lexapro Facts prednisone stopped taking side effects difference between lexapro and celexa Amoxil Without Prescription accutane timeline; symptoms of zoloft working Prednisone Delirium Driving Accidents lipitor drug cost!
lipitor is there a generic
Lexapro Vs Celexa difference between lexapro and celexa clomid with triplets Xanax And Prozac symptoms of zoloft working lipitor drug cost! Cipro 500 Mg prednisone stopped taking side effects difference between lexapro and celexa No Prescription Needed Clomid accutane timeline; symptoms of zoloft working Prednisone 20mg Side Effect lipitor drug cost! lipitor is there a generic Is Zoloft An Mao Inhibitor difference between lexapro and celexa accutane timeline; Zoloft Weight Loss symptoms of zoloft working lipitor drug cost! Prednisone Joint Pain prednisone stopped taking side effects difference between lexapro and celexa Prednisone Abuse accutane timeline; symptoms of zoloft working Genox Nolvadex Tamoxifen lipitor drug cost! lipitor is there a generic Cipro Floxin difference between lexapro and celexa accutane timeline; Cytotec Tablets symptoms of zoloft working lipitor drug cost! Zoloft Attorney prednisone stopped taking side effects
difference between lexapro and celexa
Zithromax Used For Treating accutane timeline; clomid dosage lutenizing hormone short Lexapro Weight Gain lipitor drug cost! prednisone stopped taking side effects Zithromax Z Pack difference between lexapro and celexa accutane timeline; Soma Carisoprodol symptoms of zoloft working lipitor drug cost! Lexapro And Weight Gain prednisone stopped taking side effects