When using this code for adding files:
$("#getFile").on('change', function () {
var idVal = $("#" + itemID).val();
var files = this.files;
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists('" + guidList + "')/items",
method: "POST",
....
});
for (var i = 0; i < files.length; i++) {
var file = files[x];
var lastFileName = file.name;
if (!checkIfExist(filesItems, lastFileName)) {
var fileName = Date.now() + file.name;
var getFileBuffer = function (file) {
//alert('in getFileBuffer');
var deferred = $.Deferred();
var reader = new FileReader();
reader.onload = function (e) {
deferred.resolve(e.target.result);
}
reader.onerror = function (e) {
deferred.reject(e.target.error);
}
reader.readAsArrayBuffer(file);
return deferred.promise();
}
getFileBuffer(file).then(function (buffer) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists('" + guidList + "')/items('" + idVal + "')/AttachmentFiles/add(FileName = '" + fileName + "')",
method: 'POST',
....
})
I get an error for sending a post to this address: .../_api/web/lists('9d082dbb-217c-4abb-922f-807d0f6d5dce')/items('22')/AttachmentFiles/add(FileName = 'fileName')
Do you know how to use rest API for adding attachments to a specific file by the list guid?
(When using by list name - it works)
add(FileName = '" + fileName + "')"
why do you have spaces before and after FileName. It should beadd(FileName='" + fileName + "')"