diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-04-08 23:41:43 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-04-08 23:41:43 -0400 |
| commit | f8f9c515cd9c413323f64692fd0528877a8fceed (patch) | |
| tree | e3d35d452d9555f2b0082a6f7577bb660dc33ab1 | |
| parent | 2a4266fd00a0b1327a7b24ee9807b94f0060a118 (diff) | |
uploads working
| -rw-r--r-- | app/node_modules/okservices/index.js | 7 | ||||
| -rw-r--r-- | themes/okadmin/public/js/app.js | 11 | ||||
| -rw-r--r-- | themes/okadmin/public/js/upload.js | 56 | ||||
| -rw-r--r-- | themes/okadmin/templates/partials/tail.liquid | 3 |
4 files changed, 75 insertions, 2 deletions
diff --git a/app/node_modules/okservices/index.js b/app/node_modules/okservices/index.js index 10de460..46f7ffd 100644 --- a/app/node_modules/okservices/index.js +++ b/app/node_modules/okservices/index.js @@ -20,9 +20,12 @@ function OKImageService(options) { adapter: require('skipper-s3'), key: options.s3.key, secret: options.s3.secret, - bucket: options.s3.bucket + bucket: options.s3.bucket, + headers: { + 'x-amz-acl': 'public-read' + } }, function (err, uploadedFiles) { - // + res.json(uploadedFiles); }); }); diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js new file mode 100644 index 0000000..b850466 --- /dev/null +++ b/themes/okadmin/public/js/app.js @@ -0,0 +1,11 @@ +var OKAdmin = function(){ + + + OKUpload.bind() + OKUpload.add = function(data){ + console.log(data) + } + +} + +window.app = new OKAdmin () diff --git a/themes/okadmin/public/js/upload.js b/themes/okadmin/public/js/upload.js new file mode 100644 index 0000000..d9fd5ed --- /dev/null +++ b/themes/okadmin/public/js/upload.js @@ -0,0 +1,56 @@ + +var OKUpload = { + action: "/_services/image", + + bind: function(){ + var el = document.getElementById("file") + if (! el) return + el.addEventListener("change", OKUpload.handleFileSelect) + }, + + handleFileSelect: function(e) { + e.stopPropagation(); + e.preventDefault(); + + var files = e.dataTransfer ? e.dataTransfer.files : e.target.files; + + for (var i = 0, f; f = files[i]; i++) { + if ( ! f.type.match('image.*')) { + continue; + } + OKUpload.upload(f) + } + }, + + upload: function(f){ + var fd = new FormData() + fd.append('image', f) + + var request = $.ajax({ + url: OKUpload.action, + type: "post", + data: fd, + dataType: "json", + processData: false, + contentType: false, + }) + request.done(OKUpload.success) + }, + + success: function(media){ + if (media.error) { + console.log(media.error) + return + } + OKUpload.add(media) + }, + + add: function(media){ + console.log(media) + }, + + error: function(error){ + throw error + }, + +} diff --git a/themes/okadmin/templates/partials/tail.liquid b/themes/okadmin/templates/partials/tail.liquid index 773c8d4..76d31b0 100644 --- a/themes/okadmin/templates/partials/tail.liquid +++ b/themes/okadmin/templates/partials/tail.liquid @@ -1,3 +1,6 @@ </div> {% comment %} closes container tag {% endcomment %} </body> + <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> + <script src="/_admin/js/upload.js"></script> + <script src="/_admin/js/app.js"></script> </html> |
