uploader 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +275 -0
- data/Rakefile +66 -0
- data/TODO +2 -0
- data/VERSION +1 -0
- data/app/controllers/uploader/uploads_controller.rb +122 -0
- data/app/helpers/uploader_helper.rb +17 -0
- data/app/views/uploads/_swf_javascript.html.erb +63 -0
- data/app/views/uploads/_swf_upload.html.erb +32 -0
- data/config/uploader_routes.rb +3 -0
- data/db/migrate/20090517040220_create_uploads.rb +38 -0
- data/lib/active_record/acts/uploader_upload.rb +235 -0
- data/lib/uploader/exceptions.rb +5 -0
- data/lib/uploader/initialize_routes.rb +8 -0
- data/lib/uploader/middleware/flash_session_cookie_middleware.rb +18 -0
- data/lib/uploader/mime_type_groups.rb +18 -0
- data/lib/uploader/tasks.rb +36 -0
- data/lib/uploader.rb +24 -0
- data/locales/ar.yml +17 -0
- data/locales/bg.yml +17 -0
- data/locales/ca.yml +17 -0
- data/locales/cs.yml +17 -0
- data/locales/da.yml +17 -0
- data/locales/de.yml +17 -0
- data/locales/el.yml +17 -0
- data/locales/en.yml +16 -0
- data/locales/es.yml +17 -0
- data/locales/fr.yml +17 -0
- data/locales/it.yml +17 -0
- data/locales/iw.yml +17 -0
- data/locales/ja.yml +17 -0
- data/locales/ko.yml +17 -0
- data/locales/lt.yml +17 -0
- data/locales/lv.yml +17 -0
- data/locales/nl.yml +17 -0
- data/locales/no.yml +18 -0
- data/locales/pl.yml +17 -0
- data/locales/pt.yml +17 -0
- data/locales/ro.yml +17 -0
- data/locales/ru.yml +17 -0
- data/locales/sk.yml +17 -0
- data/locales/sl.yml +17 -0
- data/locales/sr.yml +17 -0
- data/locales/sv.yml +17 -0
- data/locales/tl.yml +17 -0
- data/locales/uk.yml +17 -0
- data/locales/vi.yml +17 -0
- data/locales/zh-CN.yml +17 -0
- data/locales/zh-TW.yml +17 -0
- data/locales/zh.yml +17 -0
- data/pkg/uploader-0.1.0.gem +0 -0
- data/pkg/uploader-0.1.1.gem +0 -0
- data/pkg/uploader-0.1.2.gem +0 -0
- data/public/images/SWFUploadButton.png +0 -0
- data/public/images/file_icons/excel.gif +0 -0
- data/public/images/file_icons/file.gif +0 -0
- data/public/images/file_icons/mp3.gif +0 -0
- data/public/images/file_icons/pdf.gif +0 -0
- data/public/images/file_icons/text.gif +0 -0
- data/public/images/file_icons/word.gif +0 -0
- data/public/javascripts/swfupload/fileprogress.js +151 -0
- data/public/javascripts/swfupload/handlers.js +206 -0
- data/public/javascripts/swfupload/swfupload.cookies.js +53 -0
- data/public/javascripts/swfupload/swfupload.js +945 -0
- data/public/javascripts/swfupload/swfupload.queue.js +77 -0
- data/public/javascripts/swfupload/swfupload.swfobject.js +110 -0
- data/public/stylesheets/swfupload.css +26 -0
- data/public/swf/swfupload.swf +0 -0
- data/rails/init.rb +10 -0
- data/tasks/rails.rake +2 -0
- data/test/test_helper.rb +3 -0
- data/test/unit/upload_test.rb +5 -0
- data/uninstall.rb +0 -0
- data/uploader.gemspec +127 -0
- metadata +128 -0
@@ -0,0 +1,206 @@
|
|
1
|
+
function swfUploadPreLoad() {
|
2
|
+
var self = this;
|
3
|
+
var loading = function () {
|
4
|
+
//document.getElementById("swf_upload_UI").style.display = "none";
|
5
|
+
document.getElementById("swf_loading_content").style.display = "";
|
6
|
+
|
7
|
+
var longLoad = function () {
|
8
|
+
document.getElementById("swf_loading_content").style.display = "none";
|
9
|
+
document.getElementById("swf_long_loading").style.display = "";
|
10
|
+
};
|
11
|
+
this.customSettings.loadingTimeout = setTimeout(function () {
|
12
|
+
longLoad.call(self)
|
13
|
+
},
|
14
|
+
15 * 1000
|
15
|
+
);
|
16
|
+
};
|
17
|
+
|
18
|
+
this.customSettings.loadingTimeout = setTimeout(function () {
|
19
|
+
loading.call(self);
|
20
|
+
},
|
21
|
+
1*1000
|
22
|
+
);
|
23
|
+
}
|
24
|
+
function swfUploadLoaded() {
|
25
|
+
var self = this;
|
26
|
+
clearTimeout(this.customSettings.loadingTimeout);
|
27
|
+
//document.getElementById("swf_upload_UI").style.visibility = "visible";
|
28
|
+
//document.getElementById("swf_upload_UI").style.display = "block";
|
29
|
+
document.getElementById("swf_loading_content").style.display = "none";
|
30
|
+
document.getElementById("swf_long_loading").style.display = "none";
|
31
|
+
document.getElementById("swf_alternate_content").style.display = "none";
|
32
|
+
|
33
|
+
//document.getElementById("btnBrowse").onclick = function () { self.selectFiles(); };
|
34
|
+
document.getElementById("swf_cancel_button").onclick = function () { self.cancelQueue(); };
|
35
|
+
}
|
36
|
+
|
37
|
+
function swfUploadLoadFailed() {
|
38
|
+
clearTimeout(this.customSettings.loadingTimeout);
|
39
|
+
jQuery('#degraded_container').show();
|
40
|
+
jQuery('#swfupload_container').hide();
|
41
|
+
}
|
42
|
+
|
43
|
+
function fileQueued(file) {
|
44
|
+
try {
|
45
|
+
var progress = new FileProgress(file, this.customSettings.progressTarget);
|
46
|
+
progress.setStatus("Pending...");
|
47
|
+
progress.toggleCancel(true, this);
|
48
|
+
} catch (ex) {
|
49
|
+
this.debug(ex);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
function fileQueueError(file, errorCode, message) {
|
54
|
+
try {
|
55
|
+
if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
|
56
|
+
alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
|
60
|
+
var progress = new FileProgress(file, this.customSettings.progressTarget);
|
61
|
+
progress.setError();
|
62
|
+
progress.toggleCancel(false);
|
63
|
+
|
64
|
+
switch (errorCode) {
|
65
|
+
case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
|
66
|
+
progress.setStatus("File is too big.");
|
67
|
+
this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
|
68
|
+
break;
|
69
|
+
case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
|
70
|
+
progress.setStatus("Cannot upload Zero Byte files.");
|
71
|
+
this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
|
72
|
+
break;
|
73
|
+
case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
|
74
|
+
progress.setStatus("Invalid File Type.");
|
75
|
+
this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
|
76
|
+
break;
|
77
|
+
default:
|
78
|
+
if (file !== null) {
|
79
|
+
progress.setStatus("Unhandled Error");
|
80
|
+
}
|
81
|
+
this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
} catch (ex) {
|
85
|
+
this.debug(ex);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
function fileDialogComplete(numFilesSelected, numFilesQueued) {
|
90
|
+
try {
|
91
|
+
if (numFilesSelected > 0) {
|
92
|
+
jQuery('#' + this.customSettings.cancelButtonId).show();
|
93
|
+
}
|
94
|
+
/* I want auto start the upload and I can do that here */
|
95
|
+
this.startUpload();
|
96
|
+
} catch (ex) {
|
97
|
+
this.debug(ex);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
function uploadStart(file) {
|
102
|
+
try {
|
103
|
+
/* I don't want to do any file validation or anything, I'll just update the UI and
|
104
|
+
return true to indicate that the upload should start.
|
105
|
+
It's important to update the UI here because in Linux no uploadProgress events are called. The best
|
106
|
+
we can do is say we are uploading.
|
107
|
+
*/
|
108
|
+
var progress = new FileProgress(file, this.customSettings.progressTarget);
|
109
|
+
progress.setStatus("Uploading...");
|
110
|
+
progress.toggleCancel(true, this);
|
111
|
+
}
|
112
|
+
catch (ex) {}
|
113
|
+
|
114
|
+
return true;
|
115
|
+
}
|
116
|
+
|
117
|
+
function uploadProgress(file, bytesLoaded, bytesTotal) {
|
118
|
+
try {
|
119
|
+
var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
|
120
|
+
|
121
|
+
var progress = new FileProgress(file, this.customSettings.progressTarget);
|
122
|
+
progress.setProgress(percent);
|
123
|
+
progress.setStatus("Uploading...");
|
124
|
+
} catch (ex) {
|
125
|
+
this.debug(ex);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
function uploadSuccess(file, serverData) {
|
130
|
+
try {
|
131
|
+
var progress = new FileProgress(file, this.customSettings.progressTarget);
|
132
|
+
progress.setComplete();
|
133
|
+
progress.setStatus("Complete.");
|
134
|
+
progress.toggleCancel(false);
|
135
|
+
AddUpload(serverData);
|
136
|
+
} catch (ex) {
|
137
|
+
this.debug(ex);
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
function uploadError(file, errorCode, message) {
|
142
|
+
try {
|
143
|
+
var progress = new FileProgress(file, this.customSettings.progressTarget);
|
144
|
+
progress.setError();
|
145
|
+
progress.toggleCancel(false);
|
146
|
+
|
147
|
+
switch (errorCode) {
|
148
|
+
case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
|
149
|
+
progress.setStatus("Upload Error: " + message);
|
150
|
+
this.debug("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
|
151
|
+
break;
|
152
|
+
case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
|
153
|
+
progress.setStatus("Upload Failed.");
|
154
|
+
this.debug("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
|
155
|
+
break;
|
156
|
+
case SWFUpload.UPLOAD_ERROR.IO_ERROR:
|
157
|
+
progress.setStatus("Server (IO) Error");
|
158
|
+
this.debug("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
|
159
|
+
break;
|
160
|
+
case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
|
161
|
+
progress.setStatus("Security Error");
|
162
|
+
this.debug("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
|
163
|
+
break;
|
164
|
+
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
|
165
|
+
progress.setStatus("Upload limit exceeded.");
|
166
|
+
this.debug("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
|
167
|
+
break;
|
168
|
+
case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
|
169
|
+
progress.setStatus("Failed Validation. Upload skipped.");
|
170
|
+
this.debug("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
|
171
|
+
break;
|
172
|
+
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
|
173
|
+
// If there aren't any files left (they were all cancelled) disable the cancel button
|
174
|
+
if (this.getStats().files_queued === 0) {
|
175
|
+
document.getElementById(this.customSettings.cancelButtonId).disabled = true;
|
176
|
+
}
|
177
|
+
progress.setStatus("Cancelled");
|
178
|
+
progress.setCancelled();
|
179
|
+
break;
|
180
|
+
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
|
181
|
+
progress.setStatus("Stopped");
|
182
|
+
break;
|
183
|
+
default:
|
184
|
+
progress.setStatus("Unhandled Error: " + errorCode);
|
185
|
+
this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
|
186
|
+
break;
|
187
|
+
}
|
188
|
+
} catch (ex) {
|
189
|
+
this.debug(ex);
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
function uploadComplete(file) {
|
194
|
+
if (this.getStats().files_queued === 0) {
|
195
|
+
jQuery('#' + this.customSettings.cancelButtonId).hide();
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
// This event comes from the Queue Plugin
|
200
|
+
function queueComplete(numFilesUploaded) {
|
201
|
+
//this.customSettings.progressTarget
|
202
|
+
}
|
203
|
+
|
204
|
+
function AddUpload(data) {
|
205
|
+
upload_completed_callback(data);
|
206
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
Cookie Plug-in
|
3
|
+
|
4
|
+
This plug in automatically gets all the cookies for this site and adds them to the post_params.
|
5
|
+
Cookies are loaded only on initialization. The refreshCookies function can be called to update the post_params.
|
6
|
+
The cookies will override any other post params with the same name.
|
7
|
+
*/
|
8
|
+
|
9
|
+
var SWFUpload;
|
10
|
+
if (typeof(SWFUpload) === "function") {
|
11
|
+
SWFUpload.prototype.initSettings = function (oldInitSettings) {
|
12
|
+
return function () {
|
13
|
+
if (typeof(oldInitSettings) === "function") {
|
14
|
+
oldInitSettings.call(this);
|
15
|
+
}
|
16
|
+
|
17
|
+
this.refreshCookies(false); // The false parameter must be sent since SWFUpload has not initialzed at this point
|
18
|
+
};
|
19
|
+
}(SWFUpload.prototype.initSettings);
|
20
|
+
|
21
|
+
// refreshes the post_params and updates SWFUpload. The sendToFlash parameters is optional and defaults to True
|
22
|
+
SWFUpload.prototype.refreshCookies = function (sendToFlash) {
|
23
|
+
if (sendToFlash === undefined) {
|
24
|
+
sendToFlash = true;
|
25
|
+
}
|
26
|
+
sendToFlash = !!sendToFlash;
|
27
|
+
|
28
|
+
// Get the post_params object
|
29
|
+
var postParams = this.settings.post_params;
|
30
|
+
|
31
|
+
// Get the cookies
|
32
|
+
var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value;
|
33
|
+
for (i = 0; i < caLength; i++) {
|
34
|
+
c = cookieArray[i];
|
35
|
+
|
36
|
+
// Left Trim spaces
|
37
|
+
while (c.charAt(0) === " ") {
|
38
|
+
c = c.substring(1, c.length);
|
39
|
+
}
|
40
|
+
eqIndex = c.indexOf("=");
|
41
|
+
if (eqIndex > 0) {
|
42
|
+
name = c.substring(0, eqIndex);
|
43
|
+
value = c.substring(eqIndex + 1);
|
44
|
+
postParams[name] = value;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
if (sendToFlash) {
|
49
|
+
this.setPostParams(postParams);
|
50
|
+
}
|
51
|
+
};
|
52
|
+
|
53
|
+
}
|