diff options
| author | jules <jules@okfoc.us> | 2013-12-27 13:17:23 -0500 |
|---|---|---|
| committer | jules <jules@okfoc.us> | 2013-12-27 13:17:23 -0500 |
| commit | 631555b553110b2b7772475af04b5278f916f2b4 (patch) | |
| tree | 2563b8e53ad0e97f911fe24681e94be61c7c1309 | |
| parent | 99d7aac7bc6ec924faa5fd8db73bc6cc35cab659 (diff) | |
upload button and url
| -rw-r--r-- | js/image.js | 16 | ||||
| -rw-r--r-- | shader-gif.html | 21 |
2 files changed, 23 insertions, 14 deletions
diff --git a/js/image.js b/js/image.js index 1fd91ff..7a5240f 100644 --- a/js/image.js +++ b/js/image.js @@ -45,18 +45,12 @@ function decimalString(n){ } function noop(){} -// http://www.carbonpictures.com/bucky/data/2835/photoblaster_safe_upload.cgi.txt function uploadImage(opt){ if (! opt.blob || ! opt.filename) return; opt.username = opt.username || ""; opt.success = opt.success || noop; opt.error = opt.error || noop; - - // FormData params >> - // qqfile .. file data .. or comes in with postdata - // filename .. filename - // username .. nick var form = new FormData(); @@ -68,9 +62,15 @@ function uploadImage(opt){ req.open("POST", "/cgi-bin/im/upload"); req.onload = function(event) { if (req.status == 200) { - opt.success(req.responseText); + var res = JSON.parse(req.responseText); + if (res.success) { + opt.success(res); + } + else { + opt.error(res); + } } else { - opt.error(req.responseText); + opt.error({ success: false, error: req.status }); } }; req.send(form); diff --git a/shader-gif.html b/shader-gif.html index 07cd156..1369225 100644 --- a/shader-gif.html +++ b/shader-gif.html @@ -25,6 +25,7 @@ div { display: inline-block; padding: 10px;} #instructions.dragging iframe { pointer-events: none; } #instructions .close { position: absolute; top: 5px; right: 5px; color: #f00; padding: 3px; border: 0;background: white; font-size: 10px; line-height: 10px; } .close,.remove { cursor: pointer; } +#uploaded-url { display: none; width: 300px; } </style> </head> <body> @@ -70,6 +71,7 @@ div { display: inline-block; padding: 10px;} <button id="save" disabled>save</button> <button id="upload" disabled>upload</button> <br> + <input type="text" id="uploaded-url"> </div> <div id="instructions"><iframe src="instructions.html"></iframe><button class="close">x</button></div> @@ -378,13 +380,20 @@ function upload(){ blob: blob, filename: filename + "-" + (+new Date()) + ".gif", username: "", - success: function(msg){ - console.log(msg); - status("upload successful: " + msg) + success: function(data){ + + // data.url + // data.filesize + // data.success + + console.log(data); + status("uploaded"); + + $("#uploaded-url").show().focus().val(data.url) }, - error: function(e){ - console.log(e) - status("error uploading: " + e) + error: function(data){ + console.log(data) + status("error uploading: " + data.error) } }); } |
