Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 17th, 2012  |  syntax: None  |  size: 1.91 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <script type="text/javascript">
  2.     $(function() {
  3.         $('#uploadimageBtn').click(function() {
  4.                 $('#imageInput').click();
  5.         });
  6.  
  7.         $('#imageInput').change(function(event) {
  8.                 $('#loading-spinner').show();
  9.                 var file = $(this).val();
  10.                 var fileName = file.split("\");
  11.                 $('#uploadimageBtn-inner').html("Uploading...");
  12.                 $('#uploadForm').submit();
  13.                 event.preventDefault();
  14.         });                
  15.     });
  16. </script>
  17.  
  18. <div id="uploadimageBtn">
  19.     <g:img id="loading-spinner" style="display:none;" file="loading.gif"/>
  20.     <div id="uploadimageBtn-inner">Click to upload a file</div>
  21. </div>  
  22.  
  23. <g:form name="uploadForm" action="update" method="post" enctype="multipart/form-data">
  24.     <div style="height: 0px;width: 0px; overflow:hidden;">
  25.         <input id="imageInput" name="image" type="file" value="upload"/>
  26.     </div>
  27. </g:form>
  28.        
  29. <script type="text/javascript">
  30.     $(function() {
  31.  
  32.         $('#fineUploaderElementId').fineUploader({
  33.             request: {
  34.                 endpoint: "${createLink(controller:'uploadImage', action:'save', absolute : 'true')}",
  35.                 forceMultipart: true,
  36.                 inputName: 'image'
  37.             },
  38.             multiple: false,  // only one upload at the time
  39.             validation: {
  40.                 allowedExtensions: ['jpeg', 'jpg', 'png','gif'],  //restricted file types
  41.                 sizeLimit: 5242880 // 5 MB
  42.             },
  43.             button: $('#uploadimageBtn'),
  44.             debug: true
  45.         }).on('complete', function(event, id, filename, responseJSON){
  46.             if (responseJSON.success) {
  47.                 window.location = responseJSON.targetUrl;
  48.             }
  49.         });    
  50.  
  51.     });
  52. </script>
  53.        
  54. def save() {
  55.     def uploadImage = new UploadImage(params)
  56.  
  57.     // Get the image file from the multi-part request
  58.     def f = request.getFile('image')
  59. ...
  60. }
clone this paste RAW Paste Data