有人可以帮帮我吗!我的reader.readAsBinaryString()在IE中不起作用。 现在我在网上找到了其他一些方法,但我无法让这个工作。 有人可以帮助我改变我的方法,以便它可以工作吗?
function uploadFile(){
var accountId = document.getElementById('accountId').value;
var folderId = document.getElementById('folderId').value;
var input = document.getElementById('file-input');
var filesToUpload = input.files;
if(filesToUpload[0] == 'undefined' || filesToUpload[0] == null){
showMessage('File Not Found!','WARNING');
return;
}
///Get Account to later update the account logo id
var queryAcc = "SELECT Id, Account_Logo_Id__c FROM Account WHERE Id = '{!getAccountId}' limit 1";
var resultAcc = sforce.connection.query(queryAcc);
var recordsAcc = resultAcc.getArray("records");
var account = recordsAcc[0];
///Get existing document if exist
var docName = 'accLogo_' + accountId;
var queryDoc = "SELECT Id FROM Document WHERE Name = '"+ docName +"' limit 1";
var resultDoc = sforce.connection.query(queryDoc);
var recordsDoc = resultDoc.getArray("records");
var existingDocument = recordsDoc[0];
for(var i = 0, f; f = filesToUpload[i]; i++){
var reader = new FileReader();
reader.file = f;
reader.onerror = function(e){
switch(e.target.error.code){
case e.target.error.NOT_FOUND_ERR:
showMessage('File Not Found!','WARNING');
break;
case e.target.error.NOT_READABLE_ERR:
showMessage('File is not readable','WARNING');
break;
case e.target.error.ABORT_ERR:
break;
default:
showMessage('An error occurred reading this file.','WARNING');
};
};
reader.onabort = function(e){
showMessage('File read cancelled','WARNING');
};
reader.onload = function(e){
if(existingDocument == 'undefined' || existingDocument == null){
var doc = new sforce.SObject("Document");
doc.Name = 'accLogo_' + accountId ;
doc.Type = '.jpg';
doc.Description = 'Account Logo for account:' + accountId ;
doc.FolderId = folderId;
doc.Body = (new sforce.Base64Binary(e.target.result)).toString();
sforce.connection.create([doc],
{
onSuccess : function(result, source)
{
if (result[0].getBoolean("success"))
{
console.log("new document created with id " + result[0].id);
account.Account_Logo_Id__c = result[0].id;
var results = sforce.connection.update([account]);
showMessage('Logo uploaded succesfull', 'SUCCESS');
}
else
{
console.log("failed to create document " + result[0]);
showMessage('Insert failed: ' + result[0], 'ERROR');
}
},
onFailure : function(error, source)
{
console.log("An error has occurred " + error);
showMessage('Insert failed: ' + error, 'ERROR');
}
});
}else{
existingDocument.Body = (new sforce.Base64Binary(e.target.result)).toString();
sforce.connection.update([existingDocument],
{
onSuccess : function(result, source)
{
if (result[0].getBoolean("success"))
{
console.log("new document updated with id " + result[0].id);
account.Account_Logo_Id__c = result[0].id;
var results = sforce.connection.update([account]);
showMessage('Logo uploaded succesfull', 'SUCCESS');
}
else
{
console.log("failed to update document " + result[0]);
showMessage('Update failed: ' + result[0], 'ERROR');
}
},
onFailure : function(error, source)
{
console.log("An error has occurred " + error);
showMessage('Update failed: ' + error, 'ERROR');
}
});
}
};
reader.readAsBinaryString(f);
}
}
非常感谢你!