from twisted.internet.interfaces import IConsumer
from nevow import inevow, rend, loaders, appserver, url, tags as T
from nevow.static import File as nevow_File # TODO: merge with static.File?
-from allmydata.util import fileutil, idlib
+from allmydata.util import fileutil, idlib, observer
import simplejson
from allmydata.interfaces import IDownloadTarget, IDirectoryNode, IFileNode, \
IMutableFileNode
class UnlinkedPOSTCHKUploader(rend.Page):
- def renderHTTP(self, ctx):
- req = inevow.IRequest(ctx)
- assert req.method == "POST"
+ """'POST /uri', to create an unlinked file."""
+ docFactory = getxmlfile("unlinked-upload.xhtml")
- # "POST /uri", to create an unlinked file.
+ def __init__(self, client, req):
+ rend.Page.__init__(self)
+ # we start the upload now, and distribute notification of its
+ # completion to render_ methods with an ObserverList
+ assert req.method == "POST"
+ self._done = observer.OneShotObserverList()
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
+ d = client.upload(uploadable)
+ d.addBoth(self._done.fire)
+
+ def upload_results(self):
+ return self._done.when_fired()
+
+ def data_done(self, ctx, data):
+ d = self.upload_results()
+ d.addCallback(lambda res: "done!")
+ return d
+
+ def data_uri(self, ctx, data):
+ d = self.upload_results()
+ d.addCallback(lambda res: res.uri)
+ return d
+
+ def render_download_link(self, ctx, data):
+ d = self.upload_results()
+ d.addCallback(lambda res: T.a(href="/uri/" + urllib.quote(res.uri))
+ ["/uri/" + res.uri])
return d
class UnlinkedPOSTSSKUploader(rend.Page):
if mutable:
return UnlinkedPOSTSSKUploader(), ()
else:
- return UnlinkedPOSTCHKUploader(), ()
+ return UnlinkedPOSTCHKUploader(client, req), ()
if t == "mkdir":
return UnlinkedPOSTCreateDirectory(), ()
errmsg = "/uri accepts only PUT, PUT?t=mkdir, POST?t=upload, and POST?t=mkdir"