[tahoe-dev] hello

Zooko Wilcox-O'Hearn zooko at zooko.com
Fri Nov 2 21:33:13 UTC 2012


On Tue, Oct 30, 2012 at 9:25 AM, han zheng <z.han0903 at gmail.com> wrote:
>
> Is there a way to directly upload a local file to the "tahoe cloud" not using the web server?

Tahoe-LAFS doesn't offer any API reachable from other processes
(command-line, kernel, or remote-procedure-call) which *doesn't* route
through the webapi. The diagram "network-and-reliance-toplogy.svg" ¹
shows this architecture. Everything goes through the "Tahoe-LAFS
gateway", and the only API that the Tahoe-LAFS gateway exports is the
webapi.

¹ https://tahoe-lafs.org/trac/tahoe-lafs/browser/docs/network-and-reliance-topology.svg

Han Zheng: why do you want to upload a local file to the tahoe grid
not using the web server?


The way to accomplish that is to write some Python code that runs in
the same Python process as the Tahoe-LAFS gateway. The way that I find
easiest to do such things is to look at other code that already does
it and copy and modify that.

So, here is the code that gets run when someone makes a PUT request to
the webapi (as described in webapi.rst ²):

² https://tahoe-lafs.org/trac/tahoe-lafs/browser/git/docs/frontends/webapi.rst?rev=05d0b8b5b9247e1d0541e58250a81df89d5c9115#writing-uploading-a-file

web/root.py parses the HTTP request and decides what sort of upload
this is (mutable or immutable):

https://tahoe-lafs.org/trac/tahoe-lafs/browser/git/src/allmydata/web/root.py?annotate=blame&rev=880af4e1fd398adb290ed7cb6c56c1d2306a0481#L40

Then it calls web/unlinked.py which constructs a FileHandle object.
That object is provides the interface that the uploader expects, and
it has a handle (open file descriptor) to the file on disk from which
it will read the data while the data is being uploaded.

https://tahoe-lafs.org/trac/tahoe-lafs/browser/git/src/allmydata/web/unlinked.py?annotate=blame&rev=3d771132a843a85578dc23a6cac55b4fae09fc64#L12

Then (after an unnecessary layer of indirection that I'm skipping),
immutable/upload.py starts doing some real work: setting the encoding
parameters, deciding whether to literalize this immutable file, etc:

https://tahoe-lafs.org/trac/tahoe-lafs/browser/git/src/allmydata/immutable/upload.py?annotate=blame&rev=3a1c02cfdfd0d7ca09037c05b5e82dd3d402df40#L1543

So, if you write some Python code that invokes immutable/upload.py's
"upload()" method, and passes an "uploadable" as the argument (note
that in case shown above the "uploadable" is the FileHandle object
constructed by web/unlinked.py), then you'll upload a file directly to
the grid.

Regards,

Zooko



More information about the tahoe-dev mailing list