| [reply] [d/l] [select] |
I don't know of a way. Perhaps you could write the file to disk as it's coming in and then use the command line MySQL client to do the insert. Perhaps you could put chunks into a temporary table and then have the database assemble them when finished. In any case, I'd be pretty strongly tempted to write such files to the filesystem (which is designed for this kind of thing) and just have a record of it in the database (which is designed for that kind of thing).
| [reply] |
Maybe write the incoming data into a temporary file then use MySQL's LOAD DATA to get the stuff from the file into your database.
By default, CGI.pm does write the uploaded data into a temporary file and returns a handle to that file. However I don't know a nice way to get the name of the temporary file, which you would need to pass to LOAD DATA.
| [reply] |
The idea of doing a streaming upload into MySQL is a bad idea, because too many things can fail during the upload. Write the uploaded file to a temporary space and then use the MySQL bulk loading facility to import the data in a transaction.
If you're really hell-bent on doing it as a streaming upload, you can consider creating a pipe via mkpipe, writing to that pipe from your CGI upload process and having MySQL load from that pipe instead of a file.
| [reply] [d/l] |
Dealing with file uploads in a web environment is a real pain. I've certainly been there. Everything else the user sends you is so well behaved - just a bunch of text you can stick in a table and be done with it! It's very tempting to think that you can get away with treating file uploads the same way, but I think it's a mistake to go that way.
MySQL is not a distributed file-system and it's not tuned to handle huge files like this. This problem inserting the file without loading it into memory is really just the start of your woes. How will you get the file out again? How will you do backups of your DB now that mysqldump is producing dumps that contain every file any user ever uploaded? Will you re-invent directories at some point? Permissions too? What will you do when you want to process the uploaded files with an external tool (resizing images, transcoding video, etc)?
It's not too late to setup an NFS server! It's not as hard as you probably think, and once you have one setup you'll find other uses for it (configuration, shared code installs, etc) and stop leaning on your DB so hard.
-sam
| [reply] |