]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
webish: add POST /uri?t=upload&mutable=true
authorBrian Warner <warner@allmydata.com>
Wed, 6 Feb 2008 05:10:22 +0000 (22:10 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 6 Feb 2008 05:10:22 +0000 (22:10 -0700)
docs/webapi.txt
src/allmydata/test/test_web.py
src/allmydata/webish.py

index 2526266bca65db05960e88a3fa4a0b36e34bb4e7..afe35ccedffc3daf37612696d4ea5e6038f67125 100644 (file)
@@ -180,6 +180,13 @@ f. uploading a file
    directory, but can be used from an HTML form. The response is the file
    write cap.
 
+  POST http://localhost:8123/uri?t=upload&mutable=true
+
+   This action also uploads a file without attaching it to a virtual drive
+   directory, but creates a mutable file (SSK) instead of an immutable one.
+   The response contains the new URI that was created.
+
+
 g. creating a new directory
 
   PUT http://localhost:8123/uri?t=mkdir
index 3290e7da1273b4ddd7697db2e6f3b1392a5fb901..520dcc3841877ba7b6e03069909a4ed29fae5ebb 100644 (file)
@@ -1006,6 +1006,21 @@ class Web(WebMixin, unittest.TestCase):
         return d
     test_POST_upload_no_link_whendone.todo = "Not yet implemented."
 
+    def test_POST_upload_no_link_mutable(self):
+        d = self.POST("/uri", t="upload", mutable="true",
+                      file=("new.txt", self.NEWFILE_CONTENTS))
+        def _check(uri):
+            uri = uri.strip()
+            u = IURI(uri)
+            self.failUnless(IMutableFileURI.providedBy(u))
+            n = self.s.create_node_from_uri(uri)
+            return n.download_to_data()
+        d.addCallback(_check)
+        def _check2(data):
+            self.failUnlessEqual(data, self.NEWFILE_CONTENTS)
+        d.addCallback(_check2)
+        return d
+
     def test_POST_upload_mutable(self):
         # this creates a mutable file
         d = self.POST(self.public_url + "/foo", t="upload", mutable="true",
index 7547b3a6c726ca025f6e19ac5af6853ee2d7553a..65132317794ef0dc590b2ffe78405d6e98f860ed 100644 (file)
@@ -1229,11 +1229,20 @@ class URIPOSTHandler(rend.Page):
 
         if t in ("", "upload"):
             # "POST /uri", to create an unlinked file.
-            fileobj = req.fields["file"].file
-            uploadable = FileHandle(fileobj)
-            d = IClient(ctx).upload(uploadable)
-            d.addCallback(lambda results: results.uri)
-            # that fires with the URI of the new file
+            mutable = bool(get_arg(req, "mutable", "").strip())
+            if mutable:
+                # SDMF: files are small, and we can only upload data
+                contents = req.fields["file"]
+                contents.file.seek(0)
+                data = contents.file.read()
+                d = IClient(ctx).create_mutable_file(data)
+                d.addCallback(lambda n: n.get_uri())
+            else:
+                fileobj = req.fields["file"].file
+                uploadable = FileHandle(fileobj)
+                d = IClient(ctx).upload(uploadable)
+                d.addCallback(lambda results: results.uri)
+                # that fires with the URI of the new file
             return d
 
         if t == "mkdir":
@@ -1434,6 +1443,7 @@ class Root(rend.Page):
             "Choose a file: ",
             T.input(type="file", name="file", class_="freeform-input-file"),
             T.input(type="hidden", name="t", value="upload"),
+            " Mutable?:", T.input(type="checkbox", name="mutable"),
             T.input(type="submit", value="Upload!"),
             ]]
         return T.div[form]