diff --git a/include/class.file.php b/include/class.file.php
index 761aba16465ce8774c2fbcdde5c082720da75195..a38fab8f8fa8aa7f53081a21d31b054351dacd47 100644
--- a/include/class.file.php
+++ b/include/class.file.php
@@ -230,7 +230,7 @@ class AttachmentFile {
  * in the FILE_CHUNK_TABLE to overcome the max_allowed_packet limitation of
  * LOB fields in the MySQL database
  */
-define('CHUNK_SIZE', 256*1024); # Beware if you change this...
+define('CHUNK_SIZE', 500*1024); # Beware if you change this...
 class AttachmentChunkedData {
     function AttachmentChunkedData($file) {
         $this->_file = $file;
@@ -244,51 +244,24 @@ class AttachmentChunkedData {
         return $length;
     }
 
-    function seek($location) {
-        $this->_pos=$location;
-    }
-
-    function tell() {
-        return $this->_pos;
-    }
-
     function read($length=CHUNK_SIZE) {
         # Read requested length of data from attachment chunks
-        $buffer='';
-        while ($length > 0) {
-            $chunk_id = floor($this->_pos / CHUNK_SIZE);
-            $start = $this->_pos % CHUNK_SIZE;
-            $size = min($length, CHUNK_SIZE - $start);
-            list($block) = @db_fetch_row(db_query(
-                'SELECT SUBSTR(filedata, '.($start+1).', '.$size
-                .') FROM '.FILE_CHUNK_TABLE.' WHERE file_id='
-                .db_input($this->_file).' AND chunk_id='.$chunk_id));
-            if (!$block) return false;
-            $buffer .= $block;
-            $this->_pos += $size;
-            $length -= $size;
-        }
+        list($buffer) = @db_fetch_row(db_query(
+            'SELECT filedata FROM '.FILE_CHUNK_TABLE.' WHERE file_id='
+            .db_input($this->_file).' AND chunk_id='.$this->_pos++));
         return $buffer;
     }
 
-    function write($what) {
-        # Figure out the remaining part of the current chunk (use CHUNK_SIZE
-        # and $this->_pos, increment pointer into $what and continue to end
-        # of what
+    function write($what, $chunk_size=CHUNK_SIZE) {
         $offset=0;
         for (;;) {
-            $start = $this->_pos % CHUNK_SIZE;
-            $size = CHUNK_SIZE - $start;
-            $block = substr($what, $offset, $size);
+            $block = substr($what, $offset, $chunk_size);
             if (!$block) break;
             if (!db_query('REPLACE INTO '.FILE_CHUNK_TABLE
-                    .' SET filedata=INSERT(filedata, '.($start+1).','.$size
-                    .', 0x'.bin2hex($block)
-                    .'), file_id='.db_input($this->_file)
-                    .', chunk_id='.floor($this->_pos / CHUNK_SIZE)))
+                    .' SET filedata=0x'.bin2hex($block).', file_id='
+                    .db_input($this->_file).', chunk_id='.db_input($this->_pos++)))
                 return false;
-            $offset += $size;
-            $this->_pos += strlen($block);
+            $offset += strlen($block);
         }
         return true;
     }
diff --git a/include/upgrader/sql/15b30765-dd0022fb.patch.sql b/include/upgrader/sql/15b30765-dd0022fb.patch.sql
index 31307d655c731e2007046dad7f069892c8443288..0006139d679fdf9af8924b639b488e3edc0f2c34 100644
--- a/include/upgrader/sql/15b30765-dd0022fb.patch.sql
+++ b/include/upgrader/sql/15b30765-dd0022fb.patch.sql
@@ -6,15 +6,6 @@
  *  
  */
 
-CREATE TABLE `%TABLE_PREFIX%T_file_chunk_id` ( `id` int(11) );
--- Support up to 16MB attachments
-INSERT INTO `%TABLE_PREFIX%T_file_chunk_id` VALUES (0), (1), (2), (3), (4),
-(5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17),
-(18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29),
-(30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41),
-(42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53),
-(54), (55), (56), (57), (58), (59), (60), (61), (62), (63);
-
 DROP TABLE IF EXISTS `%TABLE_PREFIX%file_chunk`;
 CREATE TABLE `%TABLE_PREFIX%file_chunk` (
     `file_id` int(11) NOT NULL,
@@ -24,16 +15,12 @@ CREATE TABLE `%TABLE_PREFIX%file_chunk` (
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
 INSERT INTO `%TABLE_PREFIX%file_chunk` (`file_id`, `chunk_id`, `filedata`)
-    SELECT T1.`id`, T2.`id`,
-        SUBSTR(T1.`filedata`, T2.`id` * 256 * 1024 + 1, 256 * 1024)
-    FROM `%TABLE_PREFIX%file` T1, `%TABLE_PREFIX%T_file_chunk_id` T2
-    WHERE T2.`id` * 256 * 1024 < LENGTH(T1.`filedata`);
+    SELECT `id`, 0, `filedata`
+    FROM `%TABLE_PREFIX%file`;
 
 ALTER TABLE `%TABLE_PREFIX%file` DROP COLUMN `filedata`;
 OPTIMIZE TABLE `%TABLE_PREFIX%file`;
 
-DROP TABLE `%TABLE_PREFIX%T_file_chunk_id`;
-
 -- Finished with patch
 UPDATE `%TABLE_PREFIX%config`
     SET `schema_signature`='dd0022fb14892c0bb6a9700392df2de7';