|
1 | 1 | #!/usr/bin/env node
|
2 | 2 | /*
|
3 |
| - * jQuery File Upload Plugin Node.js Example 1.0 |
| 3 | + * jQuery File Upload Plugin Node.js Example 1.0.1 |
4 | 4 | * https://github.com/blueimp/jQuery-File-Upload
|
5 | 5 | *
|
6 | 6 | * Copyright 2012, Sebastian Tschan
|
|
82 | 82 | 'Access-Control-Allow-Methods',
|
83 | 83 | options.accessControl.allowMethods
|
84 | 84 | );
|
85 |
| - var handleResult = function (result) { |
86 |
| - var contentType = req.headers.accept.indexOf('application/json') !== -1 ? |
87 |
| - 'application/json' : 'text/plain'; |
88 |
| - res.writeHead(200, {'Content-Type': contentType}); |
89 |
| - res.end(JSON.stringify(result)); |
| 85 | + var handleResult = function (result, redirect) { |
| 86 | + if (redirect) { |
| 87 | + res.writeHead(302, { |
| 88 | + 'Location': redirect.replace( |
| 89 | + /%s/, |
| 90 | + encodeURIComponent(JSON.stringify(result)) |
| 91 | + ) |
| 92 | + }); |
| 93 | + res.end(); |
| 94 | + } else { |
| 95 | + res.writeHead(200, { |
| 96 | + 'Content-Type': req.headers.accept |
| 97 | + .indexOf('application/json') !== -1 ? |
| 98 | + 'application/json' : 'text/plain' |
| 99 | + }); |
| 100 | + res.end(JSON.stringify(result)); |
| 101 | + } |
90 | 102 | },
|
91 | 103 | setNoCacheHeaders = function () {
|
92 | 104 | res.setHeader('Pragma', 'no-cache');
|
|
197 | 209 | files = [],
|
198 | 210 | map = {},
|
199 | 211 | counter = 1,
|
| 212 | + redirect, |
200 | 213 | finish = function () {
|
201 | 214 | counter -= 1;
|
202 | 215 | if (!counter) {
|
203 | 216 | files.forEach(function (fileInfo) {
|
204 | 217 | fileInfo.initUrls(handler.req);
|
205 | 218 | });
|
206 |
| - handler.callback(files); |
| 219 | + handler.callback(files, redirect); |
207 | 220 | }
|
208 | 221 | };
|
209 | 222 | form.uploadDir = options.tmpDir;
|
|
213 | 226 | fileInfo.safeName();
|
214 | 227 | map[path.basename(file.path)] = fileInfo;
|
215 | 228 | files.push(fileInfo);
|
| 229 | + }).on('field', function (name, value) { |
| 230 | + if (name === 'redirect') { |
| 231 | + redirect = value; |
| 232 | + } |
216 | 233 | }).on('file', function (name, file) {
|
217 | 234 | var fileInfo = map[path.basename(file.path)];
|
218 | 235 | fileInfo.size = file.size;
|
|
0 commit comments