This action also uploads a file without attaching it to a virtual drive
directory, but can be used from an HTML form. The response is the file
- write cap.
+ read cap.
POST http://localhost:8123/uri?t=upload&mutable=true
directory, but creates a mutable file (SSK) instead of an immutable one.
The response contains the new URI that was created.
+ PUT http://localhost:8123/uri?mutable=true
+
+ This second form also accepts data from the HTTP request body, but creates
+ a mutable file (SSK) instead of an immutable one (CHK). The response
+ contains the new URI that was created.
+
g. creating a new directory
uri = uri.strip()
u = IURI(uri)
self.failUnless(IMutableFileURI.providedBy(u))
+ self.failUnless(u.storage_index in FakeMutableFileNode.all_contents)
n = self.s.create_node_from_uri(uri)
return n.download_to_data()
d.addCallback(_check)
"/uri only accepts PUT and PUT?t=mkdir")
return d
+ def test_PUT_NEWFILE_URI_mutable(self):
+ file_contents = "New file contents here\n"
+ d = self.PUT("/uri?mutable=true", file_contents)
+ def _check(uri):
+ uri = uri.strip()
+ u = IURI(uri)
+ self.failUnless(IMutableFileURI.providedBy(u))
+ self.failUnless(u.storage_index in FakeMutableFileNode.all_contents)
+ n = self.s.create_node_from_uri(uri)
+ return n.download_to_data()
+ d.addCallback(_check)
+ def _check2(data):
+ self.failUnlessEqual(data, file_contents)
+ d.addCallback(_check2)
+ return d
+
+ def _check(uri):
+ self.failUnless(uri in FakeCHKFileNode.all_contents)
+ self.failUnlessEqual(FakeCHKFileNode.all_contents[uri],
+ file_contents)
+ return self.GET("/uri/%s" % uri)
+ d.addCallback(_check)
+ def _check2(res):
+ self.failUnlessEqual(res, file_contents)
+ d.addCallback(_check2)
+ return d
+
def test_PUT_mkdir(self):
d = self.PUT("/uri?t=mkdir", "")
def _check(uri):
if t == "":
# "PUT /uri", to create an unlinked file. This is like PUT but
# without the associated set_uri.
- uploadable = FileHandle(req.content)
- 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.content
+ contents.seek(0)
+ data = contents.read()
+ d = IClient(ctx).create_mutable_file(data)
+ d.addCallback(lambda n: n.get_uri())
+ else:
+ uploadable = FileHandle(req.content)
+ 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":