<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<STYLE type=text/css> <!--@import url(scrollbar.css); --></STYLE>

<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<STYLE>                   body{FONT-SIZE:12pt; FONT-FAMILY:宋体,serif;}         </STYLE>

<META name=GENERATOR content="MSHTML 9.00.8112.16450"><BASE 
target=_blank></HEAD>
<BODY 
style="LINE-HEIGHT: 1.3; BORDER-RIGHT-WIDTH: 0px; MARGIN: 12px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" 
marginheight="0" marginwidth="0">
<DIV><FONT color=#000000 size=3 face=Verdana>Thank you, just as 
you said, I wrote some python code like this(test.py):</FONT></DIV>
<DIV><FONT size=3 
face=Verdana>----------------------------------------------------------------------------</FONT></DIV>
<DIV><FONT size=3 face=Verdana>......</FONT></DIV>
<DIV><FONT size=3 face=Verdana>if __name__ == "__main__":</FONT></DIV>
<DIV><FONT size=3 face=Verdana>    c = 
client.Client("/home/nick/.tahoe")</FONT></DIV>
<DIV><FONT size=3 face=Verdana>    uploader = 
c.getServiceNamed("uploader")</FONT></DIV>
<DIV><FONT size=3 face=Verdana>    uploadable = 
FileName("/home/nick/test.tar.gz",None)</FONT></DIV>
<DIV><FONT size=3 face=Verdana>    d = 
uploader.upload(uploadable)</FONT></DIV>
<DIV><FONT size=3 
face=Verdana>    d.addCallback(printSuccess)</FONT></DIV>
<DIV><FONT size=3 
face=Verdana>    d.addErrback(printError)</FONT></DIV>
<DIV><FONT size=3 face=Verdana></FONT> </DIV>
<DIV><FONT size=3 face=Verdana>    
reactor.callLater(10,reactor.stop)</FONT></DIV>
<DIV><FONT size=3 face=Verdana>    reactor.run()</FONT></DIV>
<DIV><FONT size=3 
face=Verdana>----------------------------------------------------------------------------</FONT></DIV>
<DIV><FONT size=3 face=Verdana></FONT> </DIV>
<DIV><FONT size=3 face=Verdana>When I ran "python test.py"(the file located in 
"/home/nick/.tahoe"), there was an Failure instance like 
this: "client gave us zero servers"</FONT></DIV>
<DIV><FONT size=3 face=Verdana></FONT> </DIV>
<DIV><FONT size=3 face=Verdana>Should I do some initialization work? and 
how?  I ran "tahoe start" before I ran "test.py"</FONT></DIV>
<DIV><FONT size=3 face=Verdana></FONT> </DIV>
<DIV><FONT size=3 face=Verdana>If I only use tahoe as backup system, I 
think uploading a file directly to the cloud is more efficient</FONT></DIV>
<DIV><FONT size=3 face=Verdana></FONT> </DIV>
<DIV> </DIV>
<DIV align=left><FONT color=#c0c0c0 size=2 face=Verdana>2012-11-03</FONT></DIV>
<DIV align=left><FONT size=2 face=Verdana>
<HR style="WIDTH: 122px; HEIGHT: 2px" id=SignNameHR align=left SIZE=2>
</FONT></DIV>
<DIV align=left><FONT color=#c0c0c0 size=2 face=Verdana><SPAN id=_FlashSignName>
<STYLE type=text/css>
body {
        font-size:12.1pt; font-family:simsun,serif;
}
</STYLE>
<!-- flashmail style begin -->
<STYLE type=text/css> <!--@import url(C:\Program Files\Netease\网易闪电邮\\data\scrollbar.css); -->
blockquote {
        margin-top:0; margin-bottom:0; margin-left:2em;
}
body {
        padding:0; margin:0;
}
</STYLE>
<BASE target=_blank><!-- flashmail style end -->
<META name=GENERATOR content="MSHTML 9.00.8112.16443">
<DIV><FONT face=Verdana>Regards,</FONT></DIV>
<DIV><FONT face=Verdana>han zheng</FONT></DIV></STATIONERY></SPAN></FONT></DIV>
<DIV><FONT size=2 face=Verdana>
<HR>
</FONT></DIV>
<DIV><FONT size=2 face=Verdana><STRONG>发件人:</STRONG>Zooko 
Wilcox-O'Hearn</FONT></DIV>
<DIV><FONT size=2 
face=Verdana><STRONG>发送时间:</STRONG>2012-11-03 05:33</FONT></DIV>
<DIV><FONT size=2 face=Verdana><STRONG>主题:</STRONG>Re: [tahoe-dev] 
hello</FONT></DIV>
<DIV><FONT size=2 face=Verdana><STRONG>收件人:</STRONG>"Tahoe-LAFS 
development"<tahoe-dev@tahoe-lafs.org></FONT></DIV>
<DIV><FONT size=2 face=Verdana><STRONG>抄送:</STRONG></FONT></DIV>
<DIV><FONT size=2 face=Verdana></FONT> </DIV>
<DIV><FONT size=2 face=Verdana>
<DIV>On Tue, Oct 30, 2012 at 9:25 AM, han zheng <z.han0903@gmail.com> wrote: </DIV>
<DIV>> </DIV>
<DIV>> Is there a way to directly upload a local file to the "tahoe cloud" not using the web server? </DIV>
<DIV> </DIV>
<DIV>Tahoe-LAFS doesn't offer any API reachable from other processes </DIV>
<DIV>(command-line, kernel, or remote-procedure-call) which *doesn't* route </DIV>
<DIV>through the webapi. The diagram "network-and-reliance-toplogy.svg" ¹ </DIV>
<DIV>shows this architecture. Everything goes through the "Tahoe-LAFS </DIV>
<DIV>gateway", and the only API that the Tahoe-LAFS gateway exports is the </DIV>
<DIV>webapi. </DIV>
<DIV> </DIV>
<DIV>¹ https://tahoe-lafs.org/trac/tahoe-lafs/browser/docs/network-and-reliance-topology.svg </DIV>
<DIV> </DIV>
<DIV>Han Zheng: why do you want to upload a local file to the tahoe grid </DIV>
<DIV>not using the web server? </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>The way to accomplish that is to write some Python code that runs in </DIV>
<DIV>the same Python process as the Tahoe-LAFS gateway. The way that I find </DIV>
<DIV>easiest to do such things is to look at other code that already does </DIV>
<DIV>it and copy and modify that. </DIV>
<DIV> </DIV>
<DIV>So, here is the code that gets run when someone makes a PUT request to </DIV>
<DIV>the webapi (as described in webapi.rst ²): </DIV>
<DIV> </DIV>
<DIV>² https://tahoe-lafs.org/trac/tahoe-lafs/browser/git/docs/frontends/webapi.rst?rev=05d0b8b5b9247e1d0541e58250a81df89d5c9115#writing-uploading-a-file </DIV>
<DIV> </DIV>
<DIV>web/root.py parses the HTTP request and decides what sort of upload </DIV>
<DIV>this is (mutable or immutable): </DIV>
<DIV> </DIV>
<DIV>https://tahoe-lafs.org/trac/tahoe-lafs/browser/git/src/allmydata/web/root.py?annotate=blame&rev=880af4e1fd398adb290ed7cb6c56c1d2306a0481#L40 </DIV>
<DIV> </DIV>
<DIV>Then it calls web/unlinked.py which constructs a FileHandle object. </DIV>
<DIV>That object is provides the interface that the uploader expects, and </DIV>
<DIV>it has a handle (open file descriptor) to the file on disk from which </DIV>
<DIV>it will read the data while the data is being uploaded. </DIV>
<DIV> </DIV>
<DIV>https://tahoe-lafs.org/trac/tahoe-lafs/browser/git/src/allmydata/web/unlinked.py?annotate=blame&rev=3d771132a843a85578dc23a6cac55b4fae09fc64#L12 </DIV>
<DIV> </DIV>
<DIV>Then (after an unnecessary layer of indirection that I'm skipping), </DIV>
<DIV>immutable/upload.py starts doing some real work: setting the encoding </DIV>
<DIV>parameters, deciding whether to literalize this immutable file, etc: </DIV>
<DIV> </DIV>
<DIV>https://tahoe-lafs.org/trac/tahoe-lafs/browser/git/src/allmydata/immutable/upload.py?annotate=blame&rev=3a1c02cfdfd0d7ca09037c05b5e82dd3d402df40#L1543 </DIV>
<DIV> </DIV>
<DIV>So, if you write some Python code that invokes immutable/upload.py's </DIV>
<DIV>"upload()" method, and passes an "uploadable" as the argument (note </DIV>
<DIV>that in case shown above the "uploadable" is the FileHandle object </DIV>
<DIV>constructed by web/unlinked.py), then you'll upload a file directly to </DIV>
<DIV>the grid. </DIV>
<DIV> </DIV>
<DIV>Regards, </DIV>
<DIV> </DIV>
<DIV>Zooko </DIV>
<DIV>_______________________________________________ </DIV>
<DIV>tahoe-dev mailing list </DIV>
<DIV>tahoe-dev@tahoe-lafs.org </DIV>
<DIV>https://tahoe-lafs.org/cgi-bin/mailman/listinfo/tahoe-dev </DIV></FONT></DIV></BODY></HTML>