I'm facing with a problem in retrieving binary of attachement list item. I use this code to get the value:
var appweburl = window.location.protocol + "//" + window.location.host
+ _spPageContextInfo.webServerRelativeUrl;
var hostweburl = _spPageContextInfo.siteAbsoluteUrl;
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: appweburl + "/_api/SP.AppContextSite(@target)/web/getfilebyserverrelativeurl('/Lists/myList/Attachments/1/myImage.jpeg')/$value?@target='" + hostweburl + "'",
method: "GET",
binaryStringResponseBody: true,
success: function (data) {
console.log(data.body);
},
error: function (err) {
alert(JSON.stringify(err));
},
});
But it returns me back this error:
GET "https://mySharePointAddress/Site/Subsite/web/_api/SP.AppContextSite(@target)/web/getfilebyserverrelativeurl('/Lists/myList/Attachments/1/myImage.jpeg')/$value?@target=%27https://mySharepointAddress/Site%27 403 (Forbidden)
Uncaught ReferenceError: ret is not defined
at Function.SP.RequestExecutorInternalSharedUtility.$13 (SP.RequestExecutor.js:2)
at Function.SP.RequestExecutor.internalProcessXMLHttpRequestOnreadystatechange (SP.RequestExecutor.js:2)
at XMLHttpRequest.<anonymous> (SP.RequestExecutor.js:2)
Can someone help me please?