mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 14:52:26 +00:00
webish: add POST /uri?t=upload&mutable=true
This commit is contained in:
parent
6afe50e2aa
commit
e5dc9a8486
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user