SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to simply upload & attach file to listItem using Javascript? And how to get/download attachments.

share|improve this question

You can find answer from here:

how to create a list item with attachment using Javascript object model

share|improve this answer
Please provide context for links and quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. – jcp Nov 25 '15 at 9:00

you can create your own file control in HTML and hook it up with the below script. I use an asynchronous loop to iterate through the files (works in IE9).

//Enable Multiple Upload Script

//startUpload(self, function (){ reloadPage(); }, event);   
$("#WSOutput").html("<b>Please wait while files are getting attached. </b>");
 var listName = claimHeaderList; // change these to suit your list and item
 selectedFilesLength =;
    length :,
    functionToLoop : function(loop, i){
            //document.write('Iteration ' + i + ' <br>');

    callback : function(){
    //document.write('All done!');



 var asyncLoop = function(o){
    var i=-1;

    var loop = function(){
        if(i==o.length){o.callback(); return;}
        o.functionToLoop(loop, i);

 function handleFileChange(listName,itemId,file,length,_callback){
 //alert(length+"selectedFilesLength:" + selectedFilesLength );
 if( !(length==selectedFilesLength))

  var deferred = $.Deferred();
 var getFileBuffer = function(file) {

  var deferred = $.Deferred();
  var reader = new FileReader();

  reader.onload = function(e) {

  reader.onerror = function(e) {


  return deferred.promise();
   getFileBuffer(file).then(function(buffer) {
  var binary = "";
  var bytes = new Uint8Array(buffer);
  var i = bytes.byteLength;
  while (i--) {
    binary = String.fromCharCode(bytes[i]) + binary;
  $("#WSOutput").html("<b>Please wait while files are getting attached. </b>").SPServices({
    operation: "AddAttachment",
    async: false,
    listName: listName,
    listItemID: itemId,
    attachment: btoa(binary),
    completefunc: function (xData, Status) {


<input type="file" multiple="multiple" class="attachmentButton" name="attachmentButton"/>
<div id="WSOutput"> &#160;</div> 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.