AnsweredAssumed Answered

file upload using rest

Question asked by ayubalfresco on Nov 25, 2014
Hi I am trying to upload file using REST. Below is the code of html page which I have deployed on tomcat. I am able to upload file, however the response appears to be downloaded and none of the call back methods are being invoked. Could some one assist me ?


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    
    <html>
    <head>
    <script src="http://localhost:9090/SharePortlet/js/jquery-1.7.1.js"></script>
    <script src="http://localhost:9090/SharePortlet/js/jquery.form.js"></script>
    
     <script>
            
     (function() {
              
               $('form').ajaxSubmit({
                
                    dataType:  'json',
                    success:   processJson,
                    complete: function(xhr) {
                            alert(xhr.responseText);
                            $("div#status").html(xhr.responseText);
                    }
             });
              
               $(document).ajaxSuccess(function (evt, jqXHR, settings) {
                      alert("Global success callback.");
                    });
    
                    $(document).ajaxError(function (evt, jqXHR, settings, err) {
                      alert("Global error callback.");
                    });
    
             })();
    
     function processJson(data) {
                // 'data' is the json object returned from the server
              
                alert(data.message);
            };
     </script>
    </head>
    <body>
    <div id="status"></div>
    <table style="width: 100%;" cellpadding="0" cellspacing="0">
            <tr>
                <td>       
    
                </td>
            </tr>
               <tr style="height: 100%;" valign="top">
                <td>
                
    <iframe name="hiddenIframe" id="hiddenIframe" style="display: none;" ></iframe>
                                  
            <form target="hiddenIframe" style="margin: 0px 10px 0px 10px" id="uplForm" enctype="multipart/form-data" method="post" action="http://localhost:8080/alfresco/service/api/upload">
    <input type="hidden" name="destination" id="destination" value="workspace://SpacesStore/8bb36efb-c26d-4d2b-9199-ab6922f53c28"/>
    <label>
          Name:
    
            </label>
    
            <br/>
    
            <input type="text" name="filename" id="filename"/><p/>
    
            <label>
    
                Description:
    
            </label>
    
            <br/>
    
            <textarea name="description" id="description"></textarea>
    
    
    
            <p/>
    
            <label>
    
                File:
    
            </label>
    
            <br/>
                            
                                <div style="margin-bottom: 20px; font-weight: bold">
                                  
                                </div>
                                <div style="margin-bottom: 10px;">
                                    Please upload your file here:
                                </div>
                                <div>
                                    
                                      <div style="margin-bottom:20px;">
                                    <input class="button" type="file" name="filedata" id="filedata"/>
                                    </div>
                                    <input id="uplBtn" type="submit" value="Upload" />
                                       </div>
                                      
                                            
                                          
                                          
                                    </form>
                                    
                  
                </td>
            </tr>
    </table>
    </body>
    </html>









Outcomes