问题描述
我AngularJS服地块写到这,我不能让它正常工作:
I wrote this in AngularJS service block and I can't get it to work properly:
app.factory('sfAttachment', ['$http', '$q', '$window', function($http, $q, $window){
var attachment = {};
//Save to server function for attachments
attachment.save = function( base64value, mimeType, currentDocTypeId, currentFilename, attachmentId ){
var data = {
"Body" : base64value,
"ContentType": mimeType,
"ParentId": currentDocTypeId,
"Name": currentFilename
};
var url = $window.__url;
var method;
var isUpdate = ($.trim(attachmentId) !== '');
if (isUpdate) {
url = url + attachmentId;
method = 'PATCH';
} else {
// Method for creation
method = 'POST';
};
var request = {
url: url,
method: method,
data: data
};
var deferred = $q.defer();
$http(request).then(function(response){
deferred.resolve(response);
console.log('file SAVED');
console.log(response);
}, function(event){
deferred.reject('The attachment could not be saved:' + event);
});
return deferred.promise;
}
return attachment;}]);
app.run(['$http','$window',function ($http, $window) {
var sessionId = $window.__sfdcSessionId;
$http.defaults.useXDomain = true;
delete $http.defaults.headers.common["X-Requested-With"];
$http.defaults.headers.common["Access-Control-Allow-Origin"] = "*";
$http.defaults.headers.common["Accept"] = "application/json";
$http.defaults.headers.common["content-type"] = "application/json";
$http.defaults.headers.common['Authorization'] = "OAuth " + sessionId ;
$http.defaults.headers.common['X-User-Agent'] = "MyClient" ;
}]) ;
我不断收到这些错误:
I keep getting these errors:
无法加载资源:服务器与400状态(坏请求)
除了这一点:
MLHtt prequest无法加载。无访问控制允许来源标头的请求的资源present。原产地因此是不允许的访问。响应有HTTP状态code 400。
我添加 https://youri--c.cs22.visual.force.com
来在Salesforce远程站点设置,但似乎仍然是造成问题。 ..
I added https://youri--c.cs22.visual.force.com
to the remote Site settings in Salesforce but that still seem to be causing issues...
有什么建议?
编辑:我想通了,我的问题,我需要白名单的第一部分 https://youri--c.cs22.visual.force.com
远程设置> CORS,而不是远程站点,但我仍然得到错误的请求错误...
I figured out the first part of my issue I needed to white list https://youri--c.cs22.visual.force.com
in Remote Settings> CORS and not remote sites but I still get the Bad request error...
推荐答案
请参阅编辑:
编辑:我想通了,我的问题的第一部分,我需要白名单远程设置> CORS,而不是远程站点,但我仍然得到错误的请求错误...
I figured out the first part of my issue I needed to white list https://youri--c.cs22.visual.force.comin Remote Settings> CORS and not remote sites but I still get the Bad request error...
这篇关于AngularJS使用Http请求saleforce附件 - 故障排除需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!