Hi First of all i would like to thank you for giving me some idea..<br>As Jorgen told i did in same way<br>Hi Jorgen<br>I created a python script in zope instance to upload multiple files and its working successfully..<br>
but its storing the file inside custom folder as we know context always refer to current location i mean our-instance/custom but when i am giving container['bin'] its giving me 'bin' key error. i want to save that file inside my instance for example<br>
<br>myzope-instance/mydir/<b><uploaded file></b> is any one have any idea<br><br><b>REQUEST=context.REQUEST<br>sentFiles = {}<br>for key in context.REQUEST.keys(): # getting all the ids<br> if key[:5]=='file.' and key[-3:]=='.id': # we finding id <a href="http://file.XXX.id">file.XXX.id</a><br>
sentFiles[REQUEST[key]]=''<br><br>for key in context.REQUEST.keys():<br> if key[:5]=='file.' and key[-3:]!='.id': #we've got a file<br> #found its id and make sure file exists<br>
if sentFiles.has_key(REQUEST[key+'.id']) and REQUEST[key].filename:<br> sentFiles[REQUEST[key+'.id']]=REQUEST[key]<br> else:<br> del sentFiles[REQUEST[key+'.id']] #remove keys that dont have files<br>
<br>for k in sentFiles.keys():<br> </b><b style="color: rgb(0, 102, 0);">context.manage_addFile(k,sentFiles[k])</b><br><b> <span style="color: rgb(0, 0, 153);">container['bin']</span>.mydir.manage_addFile(k,sentFiles[k])<br>
<br>return str(len(sentFiles)) + ' files has been uploaded successfully'</b><br><br><br><div class="gmail_quote">On Thu, Nov 6, 2008 at 7:49 PM, Jørgen Jørgensen <span dir="ltr"><<a href="mailto:gardsted@yahoo.com">gardsted@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000">
Hello Praween Kumar - <br>
I would make a pythonscript on the zope like
'locahost:8080/starinstance/myscript', taking 3 parameters, id, title
and file.<br>
remember to give it manager proxy rights (proxy in top of python script
edit screen, chose manager)<br>
script should be something like:<br>
"""<br>
container['bin'].manage_addFile(id=id, title=title, file=file)<br>
"""<br>
I havent tested, sorry;-), but at least the direction should be
something like this.<br>
then change addfileurl to:<br>
<br>
<b>addfileurl='<a href="http://localhost:8080/starinstance/bin/manage_addFile" target="_blank">http://localhost:8080/starinstance/myscript</a>'</b><br>
<br>
kind regards jorgen / denmark<br>
<br>
<br>
Praveen Kumar wrote:
<blockquote type="cite">Dear all,<div class="Ih2E3d"><br>
I want to save the file on filebased system. i am using urllib<br>
<br></div><div><div></div><div class="Wj3C7c">
here i tried with this code<br>
<br>
<b>import urllib<br>
<br>
# fill these in<br>
user='admin'<br>
password='admin1'<br>
addfileurl='<a href="http://localhost:8080/starinstance/bin/manage_addFile" target="_blank">http://localhost:8080/starinstance/bin/manage_addFile</a>'<br>
useragent="upload.py/0.1"<br>
filename='/home/praveen/Desktop/text.jpeg'<br>
filetitle='a nice test picture'<br>
<br>
class <span style="color: rgb(0, 102, 0);">MyUrlOpener</span>(<span style="color: rgb(0, 0, 153);">urllib.FancyURLopener</span>):<br>
def prompt_user_passwd(self, host, realm):<br>
return (user,password)<br>
def __init__(self, *args):<br>
self.version = useragent<br>
<span style="color: rgb(0, 102, 0);">urllib.FancyURLopener.__init__(self,
*args)</span><br>
<br>
def main():<br>
# use authentication and set the user agent<br>
urllib._urlopener = MyUrlOpener()<br>
<br>
# read the contents of filename into filebody<br>
f=open(filename)<br>
filebody=f.read()<br>
f.close<br>
<br>
# urlencode the id, title and file<br>
params = urllib.urlencode({'id': filename,<br>
'title':filetitle,<br>
'file':filebody})<br>
<br>
# send the file to zope<br>
f=urllib.urlopen(addfileurl, params)<br>
<br>
if __name__ == '__main__':<br>
main()</b><br>
<br>
when i compile this file with simple python demo.py it gives me error<br>
Traceback (most recent call last):<br>
File "demo.py", line 36, in ?<br>
main()<br>
File "demo.py", line 33, in main<br>
f=urllib.urlopen(addfileurl, params)<br>
File "/usr/lib/python2.4/urllib.py", line 84, in urlopen<br>
return opener.open(url, data)<br>
File "/usr/lib/python2.4/urllib.py", line 192, in open<br>
return getattr(self, name)(url, data)<br>
File "/usr/lib/python2.4/urllib.py", line 272, in open_http<br>
import httplib<br>
File "/usr/lib/python2.4/httplib.py", line 70, in ?<br>
import mimetools<br>
File "/usr/lib/python2.4/mimetools.py", line 6, in ?<br>
import tempfile<br>
File "/usr/lib/python2.4/tempfile.py", line 33, in ?<br>
from random import Random as _Random<br>
File "/usr/lib/python2.4/random.py", line 43, in ?<br>
from math import log as _log, exp as _exp, pi as _pi, e as _e<br></div></div><div class="Ih2E3d">
ImportError: /usr/lib/python2.4/lib-dynload/math.so: undefined symbol:
PyFPE_jbuf<br>
<br></div><div><div></div><div class="Wj3C7c">
so i compiled with this command <b style="color: rgb(153, 0, 0);">python2.4
demo.py</b> it does not give any error<br>
but it does not give me output to when i check my directory where i am
trying to save my jpeg file <b><a href="http://localhost:8080/starinstance/bin/manage_addFile" target="_blank">http://localhost:8080/starinstance/bin/manage_addFile</a>
</b>there i do not find that file it means it is not able to store
that file.<br>
<br>
i do not know what i am trying to do..could any one please give me idea
how may i store the file on file system.<br>
i created a html page<br>
<form name="demo" method="post" ENCTYPE="multipart/form-data"
ACTION=""><br>
<fieldset style="width:20%"><br>
<br>
Id:<input type="text" name="title"
id="title"/><br><br><br>
Name:<input type="text" name="name"
id="name"/><br><br><br>
Keywords:<input type="text" name="keywords"
id="keywords"/><br><br><br>
<input type="file" name="upload"
id="upload"/><br><br><br>
<input type="submit" name="submit" value="Save"
id="submit"/><br><br>
</fieldset><br>
</form><br>
once if user select any file it should store to specific location <b><a href="http://localhost:8080/starinstance/bin/manage_addFile" target="_blank">http://localhost:8080/starinstance/bin/manage_addFile</a><br>
<br>
</b>Any suggestion will be appreciable<br>
<br>
Thanks.<br>
-- <br>
Praveen Kumar<br>
Software Engineer<br>
Mahiti Infotech Pvt. Ltd.<br>
# 33-34, Hennur Cross<br>
Hennur Main Road<br>
Bangalore, India - 560043<br>
Mobile: +91 9343297314<br>
+91 9739854134<br>
<a href="http://www.mahiti.org" target="_blank">http://www.mahiti.org</a><br>
<br>
</div></div><pre><hr size="4" width="90%"><div class="Ih2E3d">
_______________________________________________
BangPypers mailing list
<a href="mailto:BangPypers@python.org" target="_blank">BangPypers@python.org</a>
<a href="http://mail.python.org/mailman/listinfo/bangpypers" target="_blank">http://mail.python.org/mailman/listinfo/bangpypers</a>
</div></pre>
</blockquote>
</div>
<p>
</p><br>_______________________________________________<br>
BangPypers mailing list<br>
<a href="mailto:BangPypers@python.org">BangPypers@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/bangpypers" target="_blank">http://mail.python.org/mailman/listinfo/bangpypers</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Praveen Kumar<br>Software Engineer<br>Mahiti Infotech Pvt. Ltd.<br># 33-34, Hennur Cross<br>Hennur Main Road<br>Bangalore, India - 560043<br>Mobile: +91 9343297314<br>
+91 9739854134<br><a href="http://www.mahiti.org">http://www.mahiti.org</a><br>