FileUpload, MySQL, Zope ZSQL problem
Tried finding an answer to this question but I can't. I'm trying to upload pictures to a MySQL database with the normal conditions: <input type="file" name="picture1"> enctype="multipart/form-data" method="post" My ZSQL method has the following DTML: <dtml-var expr=picture1.data> I've also tried the same thing with dtml-sqlvar using type=string. I'm always greeted with the following error whenever I feel I'm going to make a breakthrough: FileUpload instance has no attribute 'data' removing the ".data" section gives me: <ZPublisher.HTTPRequest.FileUpload instance at 0x932c35c> as the entry for that particular field. Is it possible?????? Am I trying the impossible??? if not... how can I make it possible to get these pictures into this database. (i'm starting to lose my cool on this computer). Thanks for any help. If it's not possible I guess I'll have to bloat my Object Database rather than my relational databse. Quince Baltimore, MD.
Hi, A quick look at the source (Zope/lib/python/Zpublisher/HTTPRequest.py) suggests that you should be accessing the filename attribute of the FileUpload instance to get the location of the uploaded file ie. something like: <dtml-var expr=picture1.filename> You can then read the contents of the file and do your insert. Also, the docstring says: File upload objects can be used just like files. So presumably you can access the file data by read() ing from picture1 directly. HTH michael
-----Original Message----- From: zope-bounces@zope.org [mailto:zope-bounces@zope.org] On Behalf Of Quince Gibson Sent: Wednesday, January 21, 2004 4:37 PM To: zope@zope.org Cc: us3media@aol.com Subject: [Zope] FileUpload, MySQL, Zope ZSQL problem
Tried finding an answer to this question but I can't. I'm trying to upload pictures to a MySQL database with the normal conditions:
<input type="file" name="picture1"> enctype="multipart/form-data" method="post"
My ZSQL method has the following DTML: <dtml-var expr=picture1.data>
I've also tried the same thing with dtml-sqlvar using type=string.
I'm always greeted with the following error whenever I feel I'm going to make a breakthrough:
FileUpload instance has no attribute 'data'
removing the ".data" section gives me: <ZPublisher.HTTPRequest.FileUpload instance at 0x932c35c> as the entry for that particular field.
Is it possible?????? Am I trying the impossible??? if not... how can I make it possible to get these pictures into this database. (i'm starting to lose my cool on this computer).
Thanks for any help. If it's not possible I guess I'll have to bloat my Object Database rather than my relational databse.
Quince Baltimore, MD.
Thanks for the quick response. I'm not sure exactly how to use read() but I did manage to find some sort of work around. But now I have another problem. I created a python script "create_file" with the following: #parameters: file_name context.manage_addProduct['OFSP'].manage_addFile(id="uploadedfile", title="", file=file_name) doc=getattr(context, "uploadedfile") context.manage_delObjects('uploadedfile') #would defeat the purpose if I didn't return doc.data # tested it and it returns the file I then called it in my ZSQL Method using: <dtml-var expr=create_file(picture1)> Also tried it in quotes: '<dtml-var expr=create_file(picture1)>' Although the script works and returns the file's data, I get the following error (changes with the file): Error Type: ProgrammingError Error Value: (1064, "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''GIF89a\x0f' at line 38") The data type I'm using in MySQL for that field is "blob." Interestingly enough, if I'm trying to upload a text file, the whole setup works. Any Suggestions? Something tells me I should be looking at MySQL and not Zope (ie. html quoting equivalent for binary data) Thanks in advance for your help. On Wed, Jan 21, 2004 at 05:02:57PM +0200, Michael Joseph wrote:
Hi,
A quick look at the source (Zope/lib/python/Zpublisher/HTTPRequest.py) suggests that you should be accessing the filename attribute of the FileUpload instance to get the location of the uploaded file ie. something like: <dtml-var expr=picture1.filename> You can then read the contents of the file and do your insert.
Also, the docstring says: File upload objects can be used just like files. So presumably you can access the file data by read() ing from picture1 directly.
HTH michael
-----Original Message----- From: zope-bounces@zope.org [mailto:zope-bounces@zope.org] On Behalf Of Quince Gibson Sent: Wednesday, January 21, 2004 4:37 PM To: zope@zope.org Cc: us3media@aol.com Subject: [Zope] FileUpload, MySQL, Zope ZSQL problem
Tried finding an answer to this question but I can't. I'm trying to upload pictures to a MySQL database with the normal conditions:
<input type="file" name="picture1"> enctype="multipart/form-data" method="post"
My ZSQL method has the following DTML: <dtml-var expr=picture1.data>
I've also tried the same thing with dtml-sqlvar using type=string.
I'm always greeted with the following error whenever I feel I'm going to make a breakthrough:
FileUpload instance has no attribute 'data'
removing the ".data" section gives me: <ZPublisher.HTTPRequest.FileUpload instance at 0x932c35c> as the entry for that particular field.
Is it possible?????? Am I trying the impossible??? if not... how can I make it possible to get these pictures into this database. (i'm starting to lose my cool on this computer).
Thanks for any help. If it's not possible I guess I'll have to bloat my Object Database rather than my relational databse.
Quince Baltimore, MD.
You're right- you're not escaping the binary data when doing your MySQL insert. You need to research escaping parameters in ZSQL methods- perhaps try using <dtml-sqlvar type=string ..> ?
-----Original Message----- From: Quince Gibson [mailto:quince@us3media.com] Sent: Wednesday, January 21, 2004 6:21 PM To: Michael Joseph Cc: zope@zope.org Subject: Re: [Zope] FileUpload, MySQL, Zope ZSQL problem
Thanks for the quick response. I'm not sure exactly how to use read() but I did manage to find some sort of work around. But now I have another problem. I created a python script "create_file" with the following: #parameters: file_name context.manage_addProduct['OFSP'].manage_addFile(id="uploadedf ile", title="", file=file_name) doc=getattr(context, "uploadedfile") context.manage_delObjects('uploadedfile') #would defeat the purpose if I didn't return doc.data # tested it and it returns the file
I then called it in my ZSQL Method using: <dtml-var expr=create_file(picture1)>
Also tried it in quotes: '<dtml-var expr=create_file(picture1)>'
Although the script works and returns the file's data, I get the following error (changes with the file): Error Type: ProgrammingError Error Value: (1064, "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''GIF89a\x0f' at line 38")
The data type I'm using in MySQL for that field is "blob."
Interestingly enough, if I'm trying to upload a text file, the whole setup works.
Any Suggestions? Something tells me I should be looking at MySQL and not Zope (ie. html quoting equivalent for binary data)
Thanks in advance for your help.
Quince Gibson wrote at 2004-1-21 09:37 -0500:
Tried finding an answer to this question but I can't. I'm trying to upload pictures to a MySQL database with the normal conditions:
<input type="file" name="picture1"> enctype="multipart/form-data" method="post"
My ZSQL method has the following DTML: <dtml-var expr=picture1.data>
I fear, some background reading about DTML would be an advantage... What should the above give you? The file content? This would be '<dtml-var expr="picture1.read()">' You get uploaded files as "ZPublisher.HTTPRequest.FileUpload" objects. Read the respective source documentation in "ZPublisher/HTTPRequest.py", for details...
I've also tried the same thing with dtml-sqlvar using type=string.
I'm always greeted with the following error whenever I feel I'm going to make a breakthrough:
FileUpload instance has no attribute 'data'
This message is as clear are an error message can be. "picture1" does not have an attribute "data". The documentation mentioned above tells you which attributes it has...
removing the ".data" section gives me: <ZPublisher.HTTPRequest.FileUpload instance at 0x932c35c> as the entry for that particular field.
The database adapter converted the file object into a string. You see the result above... -- Dieter
participants (3)
-
Dieter Maurer -
Michael Joseph -
Quince Gibson