Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var parentId = parentId;
- console.log('pId'+parentId);
- var filesToUpload = input.files;
- for(var i = 0, f; f = filesToUpload[i]; i++)
- {
- var reader = new FileReader();
- // Keep a reference to the File in the FileReader so it can be accessed in callbacks
- reader.file = f;
- reader.onerror = function(e)
- {
- switch(e.target.error.code)
- {
- case e.target.error.NOT_FOUND_ERR:
- alert('File Not Found!');
- break;
- case e.target.error.NOT_READABLE_ERR:
- alert('File is not readable');
- break;
- case e.target.error.ABORT_ERR:
- break; // noop
- default:
- alert('An error occurred reading this file.');
- };
- };
- reader.onabort = function(e)
- {
- alert('File read cancelled');
- };
- reader.onload = function(e)
- {
- var att = new sforce.SObject("Attachment");
- //sforce.connection.serverUrl = '{!$Site.Prefix}/services/Soap/u/40.0';
- att.Name = this.file.name;
- att.ContentType = this.file.type;
- att.ParentId = parentId;
- alert("hello1" + parentId);
- var binary = "";
- att.Body = (new sforce.Base64Binary(binary)).toString();
- console.log('yt'+att.Body);
- alert(att);
- sforce.connection.create([att],
- {
- onSuccess : function(result, source)
- {
- if (result[0].getBoolean("success"))
- {
- console.log("new attachment created with id " + result[0].id);
- alert(result[0].id + "success");
- }
- else
- {
- console.log("failed to create attachment " + result[0]);
- alert("fail");
- sforce.debug.open();
- }
- },
- onFailure : function(error, source)
- {
- alert("ERROR"+error);
- console.log("An error has occurred " + error+ result[0]);
- }
- });
- };
- var hello=reader.readAsArrayBuffer(f);
- }
- actionfunctionname();
- }
Add Comment
Please, Sign In to add comment