[Zope] FileUpload, MySQL, Zope ZSQL problem

Quince Gibson quince at us3media.com
Wed Jan 21 11:21:02 EST 2004


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 at zope.org [mailto:zope-bounces at zope.org] On 
> > Behalf Of Quince Gibson
> > Sent: Wednesday, January 21, 2004 4:37 PM
> > To: zope at zope.org
> > Cc: us3media at 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.
> 
> 



More information about the Zope mailing list