inserting file into external db
First, hello to the list. Second, I've recently started using Zope at work and find that it's just different enough from Perl, C, and Java to be a little confusing, so hopefully this won't be a patently obvious question. How do you convince Zope to insert a MIME file into an external db properly? Here are some code snippets of what I've tried. First, the DTML to upload the file. <form action="do_add_doc" method="post" enctype="multipart/form-data"> <table cellspacing="0" cellpadding="2" border="0"> <p>File<input type="file" name="doc_file" size="25" value="" > <input class="form-element" type="submit" name="submit" value=" Add " > Next, the DTML to process the file: <dtml-call sqlInsertFile> And the SQL to insert the file into the MySQL db (takes argument doc_file, DOC_ID is set to 'auto increment'): insert into TABLE (DOC_ID, DOC_FILE) values ('0', <dtml-sqlvar doc_file type=nb>) The file is showing up, but it's being munged at some point. Hopefully this is as simple as uuencoding the file or somesuch, but I can't figure out to get Zope to do that. I should point out that it is a requirement of this application that the documents be accessible via ODBC, hence the MySQL db (so simply storing them in Zope's db isn't an option, unfortunately). Any pointers would be much appreciated. Cory __________________________________________________ Do You Yahoo!? Spot the hottest trends in music, movies, and more. http://buzz.yahoo.com/
On Thu, 14 Jun 2001, Corbett Waddingham wrote:
And the SQL to insert the file into the MySQL db (takes argument doc_file, DOC_ID is set to 'auto increment'): insert into TABLE (DOC_ID, DOC_FILE) values ('0', <dtml-sqlvar doc_file type=nb>)
The file is showing up, but it's being munged at some point.
1) What version of ZMySQLDA are you using? For latest version see: http://sourceforge.net/projects/mysql-python 2) Munged in what way? 3) What column type are you using for DOC_FILE? -- Andy Dustman PGP: 0xC72F3F1D @ .net http://dustman.net/andy "I'd rather listen to Newton than to Mundie. He may have been dead for almost three hundred years, but despite that he stinks up the room less." -- Linus T.
1) I'm using ZMySQLDA 1.3.3. According to the link you provided, the latest version is 2.0.7. I'll check with the person who installed it to see why the older version was put in. 2)The test files I'm using are all MS Word docs and they are being output as garbage (mostly \0 with various Unicode characters). 3) DOC_FILE is a Blob. I also tried Text, but that ends up storing the following: <ZPublisher.HTTPRequest.FileUpload instance at 88315e8> (or something like it, the reference number at the end changes). Cory --- Andy Dustman <andy@dustman.net> wrote:
On Thu, 14 Jun 2001, Corbett Waddingham wrote:
And the SQL to insert the file into the MySQL db (takes argument doc_file, DOC_ID is set to 'auto increment'): insert into TABLE (DOC_ID, DOC_FILE) values ('0', <dtml-sqlvar doc_file type=nb>)
The file is showing up, but it's being munged at some point.
1) What version of ZMySQLDA are you using? For latest version see:
http://sourceforge.net/projects/mysql-python
2) Munged in what way?
3) What column type are you using for DOC_FILE?
-- Andy Dustman PGP: 0xC72F3F1D @ .net http://dustman.net/andy "I'd rather listen to Newton than to Mundie. He may have been dead for almost three hundred years, but despite that he stinks up the room less." -- Linus T.
__________________________________________________ Do You Yahoo!? Spot the hottest trends in music, movies, and more. http://buzz.yahoo.com/
On Thu, 14 Jun 2001, Corbett Waddingham wrote:
1) I'm using ZMySQLDA 1.3.3. According to the link you provided, the latest version is 2.0.7. I'll check with the person who installed it to see why the older version was put in.
Another thing to check into it is: What version of MySQL are you using on the client and server side?
2)The test files I'm using are all MS Word docs and they are being output as garbage (mostly \0 with various Unicode characters).
How is that different from a normal MS Word document? (at least half-serious here...)
3) DOC_FILE is a Blob. I also tried Text, but that ends up storing the following: <ZPublisher.HTTPRequest.FileUpload instance at 88315e8> (or something like it, the reference number at the end changes).
You probably do want a blob, since it's (at least potentially) binary data, but using a TEXT column should not produce what you saw. That's some other problem with your DTML. <ZPublisher.HTTPRequest.FileUpload instance at x> is the result of the repr() function in python, instead of str(). Also note that a normal MySQL BLOB will only hold 64KB. You may need to use MEDIUMBLOB (up to 16 MB) for something as large as a MS Word document... -- Andy Dustman PGP: 0xC72F3F1D @ .net http://dustman.net/andy "I'd rather listen to Newton than to Mundie. He may have been dead for almost three hundred years, but despite that he stinks up the room less." -- Linus T.
64k is actually sufficient for most uses. Once this is out of testing and goes into production, the column will likely be changed to a MEDIUMBLOB, but that shouldn't be an issue at this point. Thanks for pointing that out, though. So it sounds like the problem lays somewhere in how Zope is initially loading the file. Any pointers for more information? Or should I set this aside and go read up on Python for awhile before starting again? Again, thanks for your tips. Cory --- Andy Dustman <andy@dustman.net> wrote:
On Thu, 14 Jun 2001, Corbett Waddingham wrote:
1) I'm using ZMySQLDA 1.3.3. According to the link you provided, the latest version is 2.0.7. I'll check with the person who installed it to see why the older version was put in.
Another thing to check into it is: What version of MySQL are you using on the client and server side?
2)The test files I'm using are all MS Word docs and they are being output as garbage (mostly \0 with various Unicode characters).
How is that different from a normal MS Word document? (at least half-serious here...)
3) DOC_FILE is a Blob. I also tried Text, but that ends up storing the following: <ZPublisher.HTTPRequest.FileUpload instance at 88315e8> (or something like it, the reference number at the end changes).
You probably do want a blob, since it's (at least potentially) binary data, but using a TEXT column should not produce what you saw. That's some other problem with your DTML. <ZPublisher.HTTPRequest.FileUpload instance at x> is the result of the repr() function in python, instead of str(). Also note that a normal MySQL BLOB will only hold 64KB. You may need to use MEDIUMBLOB (up to 16 MB) for something as large as a MS Word document...
-- Andy Dustman PGP: 0xC72F3F1D @ .net http://dustman.net/andy "I'd rather listen to Newton than to Mundie. He may have been dead for almost three hundred years, but despite that he stinks up the room less." -- Linus T.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
__________________________________________________ Do You Yahoo!? Spot the hottest trends in music, movies, and more. http://buzz.yahoo.com/
On Thu, 14 Jun 2001, Corbett Waddingham wrote:
So it sounds like the problem lays somewhere in how Zope is initially loading the file. Any pointers for more information? Or should I set this aside and go read up on Python for awhile before starting again?
I haven't written anything that makes use of file uploads, but judging from the Zope source, that class (FileUpload) uses file object semantics, so calling it's read() method should return the entire contents as a string, which is what you need, and this is what should be passed to your Z SQL Method. -- Andy Dustman PGP: 0xC72F3F1D @ .net http://dustman.net/andy "I'd rather listen to Newton than to Mundie. He may have been dead for almost three hundred years, but despite that he stinks up the room less." -- Linus T.
I had a problem something like this, but only when I used Netscape (4.7, on Win95). With Internet Explorer it worked fine. I forget the other details right now, but see if this behavior is browser-dependent. Unfortunately, I didn't get it solved before I had to move on. But at least that would show wherein the trouble lies. Cheers, Tom P [Corbett Waddingham]
The file is showing up, but it's being munged at some point. Hopefully this is as simple as uuencoding the file or somesuch, but I can't figure out to get Zope to do that. I should point out that it is a requirement of this application that the documents be accessible via ODBC, hence the MySQL db (so simply storing them in Zope's db isn't an option, unfortunately). Any pointers would be much appreciated.
And the SQL to insert the file into the MySQL db (takes argument doc_file, DOC_ID is set to 'auto increment'): insert into TABLE (DOC_ID, DOC_FILE) values ('0', <dtml-sqlvar doc_file type=nb>)
The file is showing up, but it's being munged at some point. Hopefully this is as simple as uuencoding the file or somesuch, but I can't figure out to get Zope to do that.
looks good, maybe the database field is not a blob? also, you might want <dtml-sqlvar doc_file type=nb optional> in case nothing is sent. __________________________________________________ Do You Yahoo!? Spot the hottest trends in music, movies, and more. http://buzz.yahoo.com/
participants (4)
-
Andy Dustman -
Corbett Waddingham -
Jason Byron -
Thomas B. Passin