diff --git a/include/ajax.forms.php b/include/ajax.forms.php
index cbd0ae46e20b377697f1cd63ea186b43656f76c2..031ae8785f424e78f512dd3def65ff73a740d65e 100644
--- a/include/ajax.forms.php
+++ b/include/ajax.forms.php
@@ -91,13 +91,17 @@ class DynamicFormsAjaxAPI extends AjaxController {
         if (!$impl instanceof FileUploadField)
             Http::response(400, 'Upload to a non file-field');
 
-        return $impl->upload();
+        return JsonDataEncoder::encode(
+            array('id'=>$impl->upload())
+        );
     }
 
     function attach() {
         $field = new FileUploadField();
         $field->loadSystemDefaultConfig();
-        return $field->upload();
+        return JsonDataEncoder::encode(
+            array('id'=>$field->upload())
+        );
     }
 }
 ?>
diff --git a/include/class.forms.php b/include/class.forms.php
index af724db322d1aac0e1679efde94a235d163ee3d4..0e91683cfc7b783ecd63771fbdeeb98823a1bd8a 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -1279,7 +1279,7 @@ class FileUploadField extends FormField {
 
         $files = AttachmentFile::format($_FILES['upload'],
             // For numeric fields assume configuration exists
-            is_numeric($this->get('id')));
+            !is_numeric($this->get('id')));
         if (count($files) != 1)
             Http::response(400, 'Send one file at a time');
         $file = array_shift($files);
@@ -1289,9 +1289,9 @@ class FileUploadField extends FormField {
         //       Return HTTP/413, 415, 417 or similar
 
         if (!($id = AttachmentFile::upload($file)))
-            Http::response(500, 'Unable to store file');
+            Http::response(500, 'Unable to store file: '. $file['error']);
 
-        Http::response(200, $id);
+        return $id;
     }
 
     function getFiles() {
@@ -1762,7 +1762,7 @@ class FileUploadWidget extends Widget {
           allowedfileextensions: '<?php echo $config['extensions'];
           ?>'.split(/,\s*/),
           maxfiles: <?php echo $config['max'] ?: 20; ?>,
-          maxfilesize: <?php echo $config['filesize'] ?: 1048576 / 1048576; ?>,
+          maxfilesize: <?php echo ($config['size'] ?: 1048576) / 1048576; ?>,
           name: '<?php echo $name; ?>[]',
           files: <?php echo JsonDataEncoder::encode($files); ?>
         });});
diff --git a/js/filedrop.field.js b/js/filedrop.field.js
index 989e05bdf79262baf7a71343cd9b7f4f464bd16a..21419cfe4850762ca857bb1e383bc972b16977b3 100644
--- a/js/filedrop.field.js
+++ b/js/filedrop.field.js
@@ -55,11 +55,13 @@
       this.uploads.push(node);
       this.progressUpdated(i, file, 0);
     },
-    uploadFinished: function(i, file, response, time, xhr) {
+    uploadFinished: function(i, file, json, time, xhr) {
       var that = this;
       this.uploads.some(function(e) {
         if (e.data('file') == file) {
-          e.find('[name="'+that.options.name+'"]').val(response);
+          if (!json || !json.id)
+            return e.remove();
+          e.find('[name="'+that.options.name+'"]').val(json.id);
           e.find('.progress-bar')
             .width('100%')
             .attr({'aria-valuenow': 100})