webish: add upload/view-uri forms (not associated with any particular directory) to the welcome page. Document POST /uri?t=upload .

This commit is contained in:
Brian Warner 2008-02-05 21:44:40 -07:00
parent 66f33ee504
commit 6afe50e2aa
4 changed files with 57 additions and 18 deletions

View File

@ -166,12 +166,19 @@ f. uploading a file
PUT http://localhost:8123/uri
in: file contents
out: file write cap
in: file contents
out: file write cap
Upload a file, returning its URI as the HTTP response body. This does not
make the file visible from the virtual drive -- to do that, see section
1.h. below, or the convenience method in section 2.a..
Upload a file, using the data from the HTTP request body, and returning
the resulting URI as the HTTP response body. This does not make the file
visible from the virtual drive -- to do that, see section 1.h. below, or
the convenience method in section 2.a..
POST http://localhost:8123/uri?t=upload
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.
g. creating a new directory
@ -347,7 +354,8 @@ c. POST forms
(browsers do not know how to do PUT or DELETE). The file's contents and the
new child name will be included in the form's arguments. This can only be
used to upload a single file at a time. To avoid confusion, name= is not
allowed to contain a slash (a 400 Bad Request error will result).
allowed to contain a slash (a 400 Bad Request error will result). The
response is the file read-cap (URI) of the resulting file.
POST $URL
@ -359,7 +367,8 @@ c. POST forms
This instructs the node to upload a file into the given directory, using a
mutable file (SSK) rather than the usual immutable file (CHK). As a result,
further operations to the same $URL will not cause the identity of the file
to change.
to change. The response is the file write-cap (URI) of the resulting
mutable file.
POST $URL

View File

@ -1191,7 +1191,7 @@ class Web(WebMixin, unittest.TestCase):
# Fetch the welcome page.
d = self.GET("/")
def _after_get_welcome_page(res):
MKDIR_BUTTON_RE=re.compile('<form action="([^"]*)" method="post".*<input type="hidden" name="t" value="([^"]*)" /><input type="hidden" name="([^"]*)" value="([^"]*)" /><input type="submit" value="create" />', re.I)
MKDIR_BUTTON_RE=re.compile('<form action="([^"]*)" method="post".*<input type="hidden" name="t" value="([^"]*)" /><input type="hidden" name="([^"]*)" value="([^"]*)" /><input type="submit" value="Create Directory!" />', re.I)
mo = MKDIR_BUTTON_RE.search(res)
formaction = mo.group(1)
formt = mo.group(2)

View File

@ -56,8 +56,12 @@ tool</a> may also be useful.</div>
</table>
</div>
<div n:render="download_form"/>
<div n:render="mkdir_form"/>
<br />
<div n:render="download_form" />
<div n:render="view_form" />
<div n:render="upload_form" />
<div n:render="mkdir_form" />
</body>
</html>

View File

@ -1398,29 +1398,55 @@ class Root(rend.Page):
return ctx.tag
# this is a form where users can download files by URI
def render_download_form(self, ctx, data):
# this is a form where users can download files by URI
form = T.form(action="uri", method="get",
enctype="multipart/form-data")[
T.fieldset[
T.legend(class_="freeform-form-label")["download a file"],
"URI of file to download: ",
T.legend(class_="freeform-form-label")["Download a file"],
"URI to download: ",
T.input(type="text", name="uri"), " ",
"Filename to download as: ",
T.input(type="text", name="filename"), " ",
T.input(type="submit", value="download"),
T.input(type="submit", value="Download!"),
]]
return T.div[form]
# this is a form where users can create new directories
def render_mkdir_form(self, ctx, data):
def render_view_form(self, ctx, data):
# this is a form where users can download files by URI, or jump to a
# named directory
form = T.form(action="uri", method="get",
enctype="multipart/form-data")[
T.fieldset[
T.legend(class_="freeform-form-label")["View a file or directory"],
"URI to view: ",
T.input(type="text", name="uri"), " ",
T.input(type="submit", value="View!"),
]]
return T.div[form]
def render_upload_form(self, ctx, data):
# this is a form where users can upload unlinked files
form = T.form(action="uri", method="post",
enctype="multipart/form-data")[
T.fieldset[
T.legend(class_="freeform-form-label")["create a directory"],
T.legend(class_="freeform-form-label")["Upload a file"],
"Choose a file: ",
T.input(type="file", name="file", class_="freeform-input-file"),
T.input(type="hidden", name="t", value="upload"),
T.input(type="submit", value="Upload!"),
]]
return T.div[form]
def render_mkdir_form(self, ctx, data):
# this is a form where users can create new directories
form = T.form(action="uri", method="post",
enctype="multipart/form-data")[
T.fieldset[
T.legend(class_="freeform-form-label")["Create a directory"],
T.input(type="hidden", name="t", value="mkdir"),
T.input(type="hidden", name="redirect_to_result", value="true"),
T.input(type="submit", value="create"),
T.input(type="submit", value="Create Directory!"),
]]
return T.div[form]