问题描述
我在升级 Sugar7.8 后收到此错误,它调用了我的文件下载.
I received this error after I upgraded sugar7.8, Which calling my filedownload.
{"error":"need_login","error_message":"No valid authentication for user."}
经过一些调查发现,糖升级了 OAuth 的 API 调用.以下是我的代码:
After some Investigation found tht sugar upgraded the API calls for OAuth. Following is my CODE:
api.fileDownload(api.buildURL("Quotes/" + model.get("id") + "/pdf/download?OAuth-Token=" + api.getOAuthToken()), {
success: function() {
app.alert.show("pdf_download_api_success", {
level: "success",
messages: SUGAR.language.get('Quotes', 'LBL_QUOTE_PDF_GENERATED'),
autoClose: true
});
},});
我检查了以下网址中的详细信息:但我无法向 HTTPS 请求添加标头,有人可以帮忙吗?
I checked the detials in the Following url: But I could not able to add headder to the HTTPS request can some one help?
https://developer.sugarcrm.com/2016/11/15/security-changes-coming-in-sugar-7-8/
推荐答案
经过大量研究,我想出了解决此问题的方法.
After so much research, I came up with a solution for this issue.
注意:api.fileDownload(
使用OAuth-token
没有支持文档.
Note: There is no supporting document for api.fileDownload(
to use OAuth-token
.
所以我尝试使用 XMLHttpRequest
并且效果很好.
So i tried using XMLHttpRequest
and it worked fine.
解决方案
var request = new XMLHttpRequest();
request.open('GET', api.buildURL("YOURMODULE/" + model.get("id") + "/pdf/download"), true);
request.setRequestHeader('OAuth-Token', api.getOAuthToken()); // UR TOKEN
request.responseType = "blob";
request.onload = function (e) {
if (this.status === 200) {
// `blob` response
// create `objectURL` of `this.response` : `.pdf` as `Blob`
var file = window.URL.createObjectURL(this.response);
var a = document.createElement("a");
a.href = file;
/*request.onreadystatechange = function() {
if(this.readyState == this.HEADERS_RECEIVED) {
console.log(request.getResponseHeader("Content-Type"));
}
}*/
a.download = request.getResponseHeader("FileName");
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
};
request.send();
检查此线程可能在未来可能有更新:https://community.sugarcrm.com/message/90474-re-sugarcrm-filedownload-error-after-upgrade?commentID=90474#comment-90474
Check this thread may be in future there may be updates: https://community.sugarcrm.com/message/90474-re-sugarcrm-filedownload-error-after-upgrade?commentID=90474#comment-90474
这篇关于升级后sugarcrm文件下载错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!