我在检索附件列表项的二进制文件时遇到问题。我使用此代码来获取值:
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));
},
});
但它让我回到了这个错误:
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)
有人能帮助我吗?
答案 0 :(得分:0)
我使用jquery ajax找到了我的问题的解决方案,谢谢Henry Algus http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/