def PUTUnlinkedCHK(req, client): # "PUT /uri", to create an unlinked file. uploadable = FileHandle(req.content, client.convergence) d = client.upload(uploadable) d.addCallback(lambda results: results.uri) # that fires with the URI of the new file return d
def replace_me_with_a_child(self, req, client, replace): # a new file is being uploaded in our place. file_format = get_format(req, "CHK") mutable_type = get_mutable_type(file_format) if mutable_type is not None: data = MutableFileHandle(req.content) d = client.create_mutable_file(data, version=mutable_type) def _uploaded(newnode): d2 = self.parentnode.set_node(self.name, newnode, overwrite=replace) d2.addCallback(lambda res: newnode) return d2 d.addCallback(_uploaded) else: assert file_format == "CHK" uploadable = FileHandle(req.content, convergence=client.convergence) d = self.parentnode.add_file(self.name, uploadable, overwrite=replace) def _done(filenode): log.msg("webish upload complete", facility="tahoe.webish", level=log.NOISY, umid="TCjBGQ") if self.node: # we've replaced an existing file (or modified a mutable # file), so the response code is 200 req.setResponseCode(http.OK) else: # we've created a new file, so the code is 201 req.setResponseCode(http.CREATED) return filenode.get_uri() d.addCallback(_done) return d
def POSTUnlinkedCHK(req, client): fileobj = req.fields["file"].file uploadable = FileHandle(fileobj, client.convergence) d = client.upload(uploadable) when_done = get_arg(req, "when_done", None) if when_done: # if when_done= is provided, return a redirect instead of our # usual upload-results page def _done(upload_results, redir_to): if "%(uri)s" in redir_to: redir_to = redir_to % {"uri": urllib.quote(upload_results.uri)} return url.URL.fromString(redir_to) d.addCallback(_done, when_done) else: # return the Upload Results page, which includes the URI d.addCallback(UploadResultsPage) return d
def POSTUnlinkedCHK(req, client): fileobj = req.fields["file"].file uploadable = FileHandle(fileobj, client.convergence) d = client.upload(uploadable) when_done = get_arg(req, "when_done", None) if when_done: # if when_done= is provided, return a redirect instead of our # usual upload-results page def _done(upload_results, redir_to): if b"%(uri)s" in redir_to: redir_to = redir_to.replace( b"%(uri)s", urlquote(upload_results.get_uri()).encode("utf-8")) return url_for_string(req, redir_to) d.addCallback(_done, when_done) else: # return the Upload Results page, which includes the URI d.addCallback(UploadResultsPage) return d
def replace_me_with_a_formpost(self, req, client, replace): # create a new file, maybe mutable, maybe immutable file_format = get_format(req, "CHK") contents = req.fields["file"] if file_format in ("SDMF", "MDMF"): mutable_type = get_mutable_type(file_format) uploadable = MutableFileHandle(contents.file) d = client.create_mutable_file(uploadable, version=mutable_type) def _uploaded(newnode): d2 = self.parentnode.set_node(self.name, newnode, overwrite=replace) d2.addCallback(lambda res: newnode.get_uri()) return d2 d.addCallback(_uploaded) return d uploadable = FileHandle(contents.file, convergence=client.convergence) d = self.parentnode.add_file(self.name, uploadable, overwrite=replace) d.addCallback(lambda newnode: newnode.get_uri()) return d
def replace_me_with_a_child(self, req, client, replace): # a new file is being uploaded in our place. mutable = boolean_of_arg(get_arg(req, "mutable", "false")) if mutable: req.content.seek(0) data = req.content.read() d = client.create_mutable_file(data) def _uploaded(newnode): d2 = self.parentnode.set_node(self.name, newnode, overwrite=replace) d2.addCallback(lambda res: newnode) return d2 d.addCallback(_uploaded) else: uploadable = FileHandle(req.content, convergence=client.convergence) d = self.parentnode.add_file(self.name, uploadable, overwrite=replace) def _done(filenode): log.msg("webish upload complete", facility="tahoe.webish", level=log.NOISY, umid="TCjBGQ") if self.node: # we've replaced an existing file (or modified a mutable # file), so the response code is 200 req.setResponseCode(http.OK) else: # we've created a new file, so the code is 201 req.setResponseCode(http.CREATED) return filenode.get_uri() d.addCallback(_done) return d
def replace_me_with_a_formpost(self, req, client, replace): # create a new file, maybe mutable, maybe immutable mutable = boolean_of_arg(get_arg(req, "mutable", "false")) if mutable: data = self._read_data_from_formpost(req) d = client.create_mutable_file(data) def _uploaded(newnode): d2 = self.parentnode.set_node(self.name, newnode, overwrite=replace) d2.addCallback(lambda res: newnode.get_uri()) return d2 d.addCallback(_uploaded) return d # create an immutable file contents = req.fields["file"] uploadable = FileHandle(contents.file, convergence=client.convergence) d = self.parentnode.add_file(self.name, uploadable, overwrite=replace) d.addCallback(lambda newnode: newnode.get_uri()) return d
def close(self): u = FileHandle(self.c.f, self.convergence) d = self.parent.add_file(self.childname, u) return d