1

i am using backbone for views,bootstrap and back end as spring rest web services. I want to upload a file from from backbone view to server using spring rest webservices. Any references??

santosh karadla
  • 81
  • 1
  • 1
  • 8

1 Answers1

0

Modern browsers are capable of uploading files via AJAX while older browsers are not. If you need to support IE < 10 you will probably need to implement a form+iframe based solution.

var formData = new FormData();
formData.append('file', $('#file')[0].files[0]);

$.ajax({
  url: '/rest/endpoint',
  type: 'POST',
  enctype: 'multipart/form-data',
  processData: false, // tell jQuery not to process the data
  contentType: false, // tell jQuery not to set contentType
  data: formData,
  success: function(data) {
    console.log(data);
  }
});
Community
  • 1
  • 1
u.k
  • 3,091
  • 1
  • 20
  • 23
  • I have no idea of posting multi part data from backbone view to rest web service.when looking for a solution..i am finding backbone with rails examples mostly.please suggest some examples. of using backbone with spring rest,Thank you @u.k – santosh karadla Nov 25 '15 at 18:16
  • I would use jQuery to do that. backbone doesn't have a specific implementation for file uploading – u.k Nov 25 '15 at 19:40
  • ok i will try by implementing it through jquery,Thank you @u.k – santosh karadla Nov 26 '15 at 04:04