File uploads
Archived from the Xataface Users forum.
rtresidd — Sat Sep 15, 2012 11:26 pm
Hi
I’m having problems uploading a file to xataface and storing it into the database correctly.
The file is an excel spreadsheet that I just happened to have in my home folder to test uploads..
I can open it locally with excel without problems.
If I store a record using mysql query browser then I can retrieve it via xataface or the query browser correctly
If I use xataface to store the file then it is corrupted either way (xataface / query browser) when trying to retreive it..
The table was created with:
- Code: Select all
DROP TABLE IF EXISTS `equipment`.`BoardModificationFiles`; CREATE TABLE `equipment`.`BoardModificationFiles` ( `id_BoardModificationFiles` int(11) NOT NULL AUTO_INCREMENT, `fk_BoardModificationsId` int(11) NOT NULL, `fileBLOB` longblob, `fileBLOB_mimetype` varchar(256) DEFAULT NULL, `fileBLOB_filename` varchar(256) DEFAULT NULL, PRIMARY KEY (`id_BoardModificationFiles`), KEY `F_idx` (`fk_BoardModificationsId`), CONSTRAINT `Fk_BoardModificationFiles_BoardModification` FOREIGN KEY (`fk_BoardModificationsId`) REFERENCES `BoardModifications` (`id_BoardModifications`) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=latin1;
I’ve created a fields.ini file for the table with:
- Code: Select all
[fileBLOB] Type = container widget:type = file
The very first time I try to retreive a file from xataface I get an incorrect filename and dud content type like:
- Code: Select all
Content-disposition: attachment; filename="BoardModificationFiles_fileBLOB_2012_09_16_13_04_36" Content-Type: CDF V2 Document, corrupt: Can't read directory
But If I click on the same link again I get:
- Code: Select all
Content-disposition: attachment; filename="Price_List_11310_Worldwide.xls" Content-Type: application/vnd.ms-excel
??? Not sure what is happening there for a start
But no matter what I can’t seem to get a workig file from xataface
I’ve tried making other very simple spreadsheets up to 500k in size.. simply filled with a bunch of ones in cells.. and they all seem to be ok..
There is something about the way this xls file is getting converted to a BLOB that is giving greif but I’m not sure what..
I’ll try attaching it and seeing if I can retrieve it from this phpbb..
hmm nope 256k limit I’ll see if I can create a shrunk version that fails..
While reducing the file size I decide to keep trimming it down until the probelm went away.
From what I can see there is somethig to do with the formatting of a cell that is causing the problem.
If I delete the data in that cell or change the format to something else eg default currency it all works ok…
BUT I still only get an issue when the file goes through xataface..
One way I noticed that it is going to fail is that the content type always failed the first time I tried to view the file..eg:
Content-Type: CDF V2 Document, corrupt: Can’t read directory
The next time I viewed the same file I get:
Content-Type: application/vnd.ms-excel
but it is still a dud file…
With ones that worked:
The first time I view the file I get a dud filename BUT I get a correct Content type of:
Content-Type: application/vnd.ms-excel
Thing is changing the format of that cell results in a huge change to the entire file..
So something is odd, but it doesn’t explain why excel is happy with the file until it goes through xataface..
rtresidd — Sun Sep 16, 2012 9:41 pm
Hi Steve
I’ve semi worked around the first click not loading issue on a file that I was having…
It seems that the path that loads the file out of the database into the temp folder in blob.php resulted in a dud?? $record value that didn’t contain values for the mimetype and filename fields..
eg $record->getValue($field[‘mimetype’], $index) returned an empty value… I’ve confirmed that $field[‘mimetype’] contained the correct field name..
I really can’t see why it is empty?
The only additional column is the blob column and that seems to work fine in the $record->getValue call as the file in temp ends up with the correct contents from what I can see..
Once the file is in the temp folder (eg after the first click failed) then the record set is loaded via a different path and doesn’t include the blob column.. that path worked fine..
My hack for the moment was to unset the $record variable at the end of where the file gets written to the temp location..
This allowed the code a few more lines down to get the record again.. minus the blob field and everything worked as expected..
I wasn’t seeing the exception “Could not find mimetype for field ‘$fieldname’” when on a server at home that I duplicated the webpage on for testing on a later installation base.. Fedora 16
It just resulted in a dud filename for the first click..
This may be some odd issue with different php versions / mysql server versions, but I’m not sure how to dig deeper in that regard..
very odd….
Richard