Permalink
Browse files

Improved blobstore implementation, a simple example works!

This is work in progress, the API will probably change.
  • Loading branch information...
1 parent 8e5be75 commit ae4f086cbc2e8700303fa54167fcbdcb3f795623 @gmosx gmosx committed Dec 23, 2009
View
53 README.md
@@ -49,8 +49,59 @@ The Python ext/db api is supported. The API is slightly different to better fit
Blobstore
---------
-NOT implemented yet.
+form:
+
+ var blobstore = require("google/appengine/api/blobstore");
+
+ exports.GET = function(env) {
+ return {data: {
+ uploadURL: blobstore.createUploadUrl("/test")
+ }}
+ }
+
+ <form action="{uploadURL}" method="POST" enctype="multipart/form-data">
+ <p>
+ <input type="file" name="file" />
+ </p>
+ <p>
+ <button type="submit">Upload</button>
+ </p>
+ </form>
+
+upload:
+
+ var blobstore = require("google/appengine/api/blobstore");
+
+ exports.GET = function(env) {
+ return {data: {
+ uploadURL: blobstore.createUploadUrl("/save")
+ }}
+ }
+
+save:
+
+ var blobstore = require("google/appengine/api/blobstore");
+
+ exports.POST = function(env) {
+ var blobs = blobstore.getUploadedBlobs(env);
+
+ return {
+ status : 303,
+ headers : {
+ "Location": "/serve?key=" + blobs.file.toString()
+ }
+ };
+ }
+serve:
+
+ var blobstore = require("google/appengine/api/blobstore");
+
+ exports.GET = function(env) {
+ var params = new Request(env).GET();
+ return blobstore.serve(params.key, env);
+ }
+
Images
------
View
33 lib/google/appengine/api/blobstore.js
@@ -16,6 +16,10 @@ var JBlobstoreServiceFactory = Packages.com.google.appengine.api.blobstore.Blobs
var DATASTORE_TYPES = require("google/appengine/api/datastore/types");
BlobKey = DATASTORE_TYPES.BlobKey;
+exports.BLOB_INFO_KIND = "__BlobInfo__";
+exports.BLOB_KEY_HEADER = "X-AppEngine-BlobKey";
+exports.UPLOAD_INFO_CREATION_HEADER = "X-AppEngine-Upload-Creation";
+
exports.createUploadUrl = function(successPath) {
return String(jservice.createUploadUrl(successPath));
};
@@ -38,3 +42,32 @@ exports.remove = exports.DELETE = function(blobKeys) {
jservice["delete"](new JBlobKey(blobKeys.toString()));
}
};
+
+//------------------------------------------------------------------------------
+// Extension of the Python API, converted from the Java API.
+
+/**
+ */
+exports.getUploadedBlobs = function(env) {
+ var map = jservice.getUploadedBlobs(env["jack.servlet_request"]),
+ blobKeys = {};
+
+ for (var i in Iterator(map.entrySet())){
+ var blobKey = new BlobKey(i.getValue());
+ blobKeys[String(i.getKey())] = new BlobKey(String(i.getValue().getKeyString()));
+ }
+
+ return blobKeys;
+};
+
+/**
+ */
+exports.serve = function(blobKey, env) {
+ jservice.serve(new JBlobKey(blobKey.toString()), env["jack.servlet_response"]);
+
+ return {
+ headers: {
+ "X-Jack-Send-Java-Response": "true"
+ }
+ }
+};
View
4 lib/google/appengine/api/datastore/types.js
@@ -114,8 +114,8 @@ var BlobKey = exports.BlobKey = function(blobKey) {
this.blobKey = blobKey;
}
-BlobKey.toString = function() {
- return this.blobKey();
+BlobKey.prototype.toString = function() {
+ return this.blobKey;
}
View
4 lib/google/appengine/ext/blobstore.js
@@ -50,6 +50,10 @@ exports.get = function(blobKey) {
return BlobInfo.get(blobKey);
}
+// EXTENSION of the python API.
+exports.sendBlob = function() {
+}
+
/**
* Add references to blobs to domain models using BlobReferenceProperty:
*
View
0 lib/google/appengine/ext/blobstore/downloadapp.js
No changes.
View
0 lib/google/appengine/ext/blobstore/uploadapp.js
No changes.

0 comments on commit ae4f086

Please sign in to comment.