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
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",
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":
"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]