Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Wrap files array in an object for the JSON response.

Sample response:
{"files":[{"name":"cat.jpg","size":464885,"url":"http:\/\/example.org\/f
iles\/cat.jpg","thumbnail_url":"http:\/\/example.org\/files\/thumbnail\/
cat.jpg","delete_url":"http:\/\/example.org\/files\/cat.jpg","delete_typ
e":"DELETE"}]}
  • Loading branch information...
commit fb455d8fe8365b0f4e8df84d7d6bdd6b739e0660 1 parent 41d7d61
@blueimp authored
View
21 js/jquery.fileupload-ui.js
@@ -1,5 +1,5 @@
/*
- * jQuery File Upload User Interface Plugin 6.11.1
+ * jQuery File Upload User Interface Plugin 7.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
@@ -139,12 +139,12 @@
// Callback for successful uploads:
done: function (e, data) {
var that = $(this).data('fileupload'),
+ files = that._getFilesFromResponse(data),
template;
if (data.context) {
data.context.each(function (index) {
- var file = ($.isArray(data.result) &&
- data.result[index]) ||
- {error: 'Empty file upload result'};
+ var file = files[index] ||
+ {error: 'Empty file upload result'};
if (file.error) {
that._adjustMaxNumberOfFiles(1);
}
@@ -164,8 +164,8 @@
);
});
} else {
- if ($.isArray(data.result)) {
- $.each(data.result, function (index, file) {
+ if (files.length) {
+ $.each(files, function (index, file) {
if (data.maxNumberOfFilesAdjusted && file.error) {
that._adjustMaxNumberOfFiles(1);
} else if (!data.maxNumberOfFilesAdjusted &&
@@ -175,7 +175,7 @@
});
data.maxNumberOfFilesAdjusted = true;
}
- template = that._renderDownload(data.result)
+ template = that._renderDownload(files)
.appendTo(that.options.filesContainer);
that._forceReflow(template);
that._transition(template).done(
@@ -307,6 +307,13 @@
}
},
+ _getFilesFromResponse: function (data) {
+ if (data.result && $.isArray(data.result.files)) {
+ return data.result.files;
+ }
+ return [];
+ },
+
// Link handler, that allows to download files
// by drag & drop of the links to the desktop:
_enableDragToDesktop: function () {
View
8 js/main.js
@@ -1,5 +1,5 @@
/*
- * jQuery File Upload Plugin JS Example 6.11
+ * jQuery File Upload Plugin JS Example 7.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
@@ -75,10 +75,8 @@ $(function () {
dataType: 'json',
context: $('#fileupload')[0]
}).done(function (result) {
- if (result && result.length) {
- $(this).fileupload('option', 'done')
- .call(this, null, {result: result});
- }
+ $(this).fileupload('option', 'done')
+ .call(this, null, {result: result});
});
}
View
6 server/gae-go/app/main.go
@@ -1,5 +1,5 @@
/*
- * jQuery File Upload Plugin GAE Go Example 2.1.3
+ * jQuery File Upload Plugin GAE Go Example 3.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
@@ -216,7 +216,9 @@ func get(w http.ResponseWriter, r *http.Request) {
}
func post(w http.ResponseWriter, r *http.Request) {
- b, err := json.Marshal(handleUploads(r))
+ result := make(map[string][]*FileInfo, 1)
+ result["files"] = handleUploads(r)
+ b, err := json.Marshal(result)
check(err)
if redirect := r.FormValue("redirect"); redirect != "" {
if strings.Contains(redirect, "%s") {
View
5 server/gae-python/main.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# jQuery File Upload Plugin GAE Python Example 1.1.5
+# jQuery File Upload Plugin GAE Python Example 2.0
# https://github.com/blueimp/jQuery-File-Upload
#
# Copyright 2011, Sebastian Tschan
@@ -117,7 +117,8 @@ def get(self):
def post(self):
if (self.request.get('_method') == 'DELETE'):
return self.delete()
- s = json.dumps(self.handle_upload(), separators=(',',':'))
+ result = {'files': self.handle_upload()}
+ s = json.dumps(result, separators=(',',':'))
redirect = self.request.get('redirect')
if redirect:
return self.redirect(str(
View
10 server/node/server.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node
/*
- * jQuery File Upload Plugin Node.js Example 1.0.4
+ * jQuery File Upload Plugin Node.js Example 2.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2012, Sebastian Tschan
@@ -200,7 +200,7 @@
files.push(fileInfo);
}
});
- handler.callback(files);
+ handler.callback({files: files});
});
};
UploadHandler.prototype.post = function () {
@@ -217,7 +217,7 @@
files.forEach(function (fileInfo) {
fileInfo.initUrls(handler.req);
});
- handler.callback(files, redirect);
+ handler.callback({files: files}, redirect);
}
};
form.uploadDir = options.tmpDir;
@@ -273,10 +273,10 @@
Object.keys(options.imageVersions).forEach(function (version) {
fs.unlink(options.uploadDir + '/' + version + '/' + fileName);
});
- handler.callback(!ex);
+ handler.callback({success: !ex});
});
} else {
- handler.callback(false);
+ handler.callback({success: false});
}
};
if (options.ssl) {
View
18 server/php/UploadHandler.php
@@ -1,6 +1,6 @@
<?php
/*
- * jQuery File Upload Plugin PHP Class 5.19.2
+ * jQuery File Upload Plugin PHP Class 6.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
@@ -657,11 +657,11 @@ public function get($print_response = true) {
}
$file_name = $this->get_file_name_param();
if ($file_name) {
- $info = $this->get_file_object($file_name);
+ $response = array('file' => $this->get_file_object($file_name));
} else {
- $info = $this->get_file_objects();
+ $response = array('files' => $this->get_file_objects());
}
- return $this->generate_response($info, $print_response);
+ return $this->generate_response($response, $print_response);
}
public function post($print_response = true) {
@@ -682,12 +682,12 @@ public function post($print_response = true) {
$content_range = isset($_SERVER['HTTP_CONTENT_RANGE']) ?
preg_split('/[^0-9]+/', $_SERVER['HTTP_CONTENT_RANGE']) : null;
$size = $content_range ? $content_range[3] : null;
- $info = array();
+ $files = array();
if ($upload && is_array($upload['tmp_name'])) {
// param_name is an array identifier like "files[]",
// $_FILES is a multi-dimensional array:
foreach ($upload['tmp_name'] as $index => $value) {
- $info[] = $this->handle_file_upload(
+ $files[] = $this->handle_file_upload(
$upload['tmp_name'][$index],
$file_name ? $file_name : $upload['name'][$index],
$size ? $size : $upload['size'][$index],
@@ -700,7 +700,7 @@ public function post($print_response = true) {
} else {
// param_name is a single object identifier like "file",
// $_FILES is a one-dimensional array:
- $info[] = $this->handle_file_upload(
+ $files[] = $this->handle_file_upload(
isset($upload['tmp_name']) ? $upload['tmp_name'] : null,
$file_name ? $file_name : (isset($upload['name']) ?
$upload['name'] : null),
@@ -713,7 +713,7 @@ public function post($print_response = true) {
$content_range
);
}
- return $this->generate_response($info, $print_response);
+ return $this->generate_response(array('files' => $files), $print_response);
}
public function delete($print_response = true) {
@@ -730,7 +730,7 @@ public function delete($print_response = true) {
}
}
}
- return $this->generate_response($success, $print_response);
+ return $this->generate_response(array('success' => $success), $print_response);
}
}
View
6 test/test.js
@@ -1,5 +1,5 @@
/*
- * jQuery File Upload Plugin Test 6.11
+ * jQuery File Upload Plugin Test 7.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
@@ -18,8 +18,8 @@ $(function () {
QUnit.done = function () {
// Delete all uploaded files:
var url = $('#fileupload').prop('action');
- $.getJSON(url, function (files) {
- $.each(files, function (index, file) {
+ $.getJSON(url, function (result) {
+ $.each(result.files, function (index, file) {
$.ajax({
url: url + '?file=' + encodeURIComponent(file.name),
type: 'DELETE'
Please sign in to comment.
Something went wrong with that request. Please try again.