0

I am using Rest api to upload the attachments

function uploadattachment(itemId, listname) {
    if ($("#ticketAttachments")[0].files.length > 0) {
        $($("#ticketAttachments")[0].files).each(function (i, file) {
                getFileBuffer(file).then(function (buffer) {
                    $.ajax({
                        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listname + "')/items(" + itemId + ")/AttachmentFiles/add(FileName='" + file.name + "')",
                        method: 'POST',
                        data: buffer,
                        processData: false,
                        headers: {
                            "Accept": "application/json; odata=verbose",
                            "content-type": "application/json; odata=verbose",
                            "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value
                        },
                        success: function () {
                            if ($("#ticketAttachments")[0].files.length == i + 1) {
                                RefreshPage();
                            }
                        },
                        error: function (data) {
                            console.log(data);
                        }
                    });
                });
        });
    }
    else {
        RefreshPage();
    }
};

This one works for uploading single file, but when I have 2 or more files, it goes to the error part giving the below error

"{" error ": {" code ":" - 2130246326, Microsoft.SharePoint.SPException "," message ": {" lang ":" en-US "," value ":" Registration conflict \ n \ nYour changes conflict with those made by another user at the same time. If you want your changes to be applied, click Previous in your web browser, refresh the page and resubmit them. "}}}"

Not sure what I have missed. Can someone please advise?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.