java - How to send file from one server to another using ajax andJava? -


i want send file 1 server using ajax , java. code not working intent. suggestions helpful.

this table listing files should sent server.

<table id="example" class="display" cellspacing="0" width="100%">     <thead>     <tr>         <th>id</th>         <th>filename</th>         <th>upload central server</th>     </tr>     </thead>     <tbody>     <tr>         <td>1</td>         <td><input type="text" value="file:///home/bgautam/documents/019.dcm.tar.xz" name="file" id="file"/></td>         <td><button type="button" class="btn btn-success upload">upload</button></td>     </tr> 

this ajax code used send request server..

<script>     $(document).ready(function() {         $('#example').datatable();           $(".upload").click(function () {             var formdata= new formdata();               //var files=$(this).closest('file').prev().text();             var files=$('#file').val();             formdata.append('file',new file([""],files));             $.ajax({                 type:'post',                 url:'/send-to-server',                 data:formdata,                 enctype:false,                 cache:false,                 headers: {'content-type': 'multipart/form-data; boundary=----webkitformboundaryj6q2vg5tmufgosqg',                 'cache-control':'no-cache'},                 processdata:false,                  success:function (data) {                     console.log(data);                 },                 error:function(data){                     console.log(data);                 }              });         });     } );  </script> 

this code used file server.

@restcontroller @crossorigin public class indexcontroller {     @postmapping("/send-to-server")     public responseentity<?> uploadfiles(@requestparam(name="files",required = true) multipartfile files)     {         system.out.println("i inside server");         system.out.println(files.getoriginalfilename());         system.out.println(files.getsize());         if(files.getoriginalfilename().endswith(".xz")) {             jsonobject jsonobject = new jsonobject();             jsonobject.put("filename", files.getoriginalfilename());             try {                 string filename = files.getname();                 string decompressionresult= new xzcompressordecompressor().decompression(new convertermultiparttofile().convert(files));                // files.write(paths.get("/bishalg/music"), file.getbytes());                 if(decompressionresult.contains("success")) {                     jsonobject.put("status", "success");                 }                 else{                     jsonobject.put("status","failure in decompressing file");                 }             } catch (exception e) {                 jsonobject.put("status", "failure with\n " + e.getmessage());             }             return new responseentity<>(jsonobject, httpstatus.ok);         }         else{             jsonobject jsonobject = new jsonobject();             jsonobject.put("filename", files.getoriginalfilename());             jsonobject.put("status", "failed!! please send compressed file.");             return new responseentity<>(jsonobject,httpstatus.no_content);         }     } } 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -