Hi it's me again, I had a look on the FileLibrary and it's functionality to import a file is quit close to that what I got in mind ... but unfortunately only close, not exactly: I my situation I got a dynamically created pdf File (via mysql/cocoon). All I want is to save this dynamically created file somewhere on the server (it is the same for cocoon and Zope) or better save the generated pdf File directly to the Zope File Library. But how could I do it ? I do not want to save the pdf first on my local system and do from there the import to Zope, like it is possible with the simple form <import file .... >. Thanks in advance J.
Jessica Niewint writes:
I had a look on the FileLibrary and it's functionality to import a file is quit close to that what I got in mind ... but unfortunately only close, not exactly: I my situation I got a dynamically created pdf File (via mysql/cocoon). All I want is to save this dynamically created file somewhere on the server (it is the same for cocoon and Zope) or better save the generated pdf File directly to the Zope File Library. But how could I do it ? I do not want to save the pdf first on my local system and do from there the import to Zope, like it is possible with the simple form <import file .... >. I do not precisely understand your need.
Somehow, the file must come to Zope. When it comes from a "MySQL" database, then you get the files content and pass this as a string to "manage_addFile". It will create a file object with the given string as content. You may need to specify "content_type" as guessing it is more difficult from a string than a "ZPublisher.HTTPRequest.FileUpload" instance. You can call "manage_addFile" in e.g. a Python Script or External Method (it probably will look somewhat like: "destination.manage_addProduct['OFSP'].manage_addFile(...)") When your file comes via HTTP, you send the files content in a POST request to Zope. When the generation is done with Python, I suggest to use "ZPublisher.Client" as HTTP client. When it is done in e.g. Java, there (probably) are similar tools to send HTTP POST requests. Dieter
Ok I did the following: in my url I call the manage_addFile like this: <a href="http://my.server.com:8080/test/manage_addFile?id=myZope.pdf&file=/usr/exchange/my.pdf">LINK</a> but in this case Zope insert the Path information '/usr/exchange/my.pdf' ...and not the file itself. I quit sure this is stupid mistake ...
Somehow, the file must come to Zope.
When it comes from a "MySQL" database, then you get the files content and pass this as a string to "manage_addFile". It will create a file object with the given string as content. You may need to specify "content_type" as guessing it is more difficult from a string than a "ZPublisher.HTTPRequest.FileUpload" instance. You can call "manage_addFile" in e.g. a Python Script or External Method (it probably will look somewhat like: "destination.manage_addProduct['OFSP'].manage_addFile(...)")
When your file comes via HTTP, you send the files content in a POST request to Zope. When the generation is done with Python, I suggest to use "ZPublisher.Client" as HTTP client. When it is done in e.g. Java, there (probably) are similar tools to send HTTP POST requests.
Dieter
Jessica Niewint writes:
Ok I did the following: in my url I call the manage_addFile like this: <a href="http://my.server.com:8080/test/manage_addFile?id=myZope.pdf&file=/usr/exchange/my.pdf">LINK</a> but in this case Zope insert the Path information '/usr/exchange/my.pdf' ...and not the file itself. I quit sure this is stupid mistake ... "<a href..>" following results is a "GET" request.
You must use a POST request. Its "Content-Type" must be "multipart/form-data" and you must send the file content and not its name. This is best done with a higher level tool, such a "ZPublisher.Client", than by hand. In HTML, you can get this with a <form method=POST enctype="multipart/form-data" action="...manage_addFile"> ... <input type=file name=file> ... </form> For security reasons, the browser will not allow you to preset the file name but your user must select the file with a file dialog. You might (I do not know) be able to work around this with Javascript. Dieter
participants (2)
-
Dieter Maurer -
Jessica Niewint