You need to sign in to do that
Don't have an account?
Sergio Mac-Intosh
How can i resize the size of my attachment in javascript.
Hi,
I got some functionality which uploads files from a visualforce page.
The problem is that mobile pictures are always to big. Because of this Salesforce won't accept the base64 because the size is to big.
How can i resize this before uploading. For small images the functionality works perfect.
Code atm:
Javascript:
Thanks in Advance!
I got some functionality which uploads files from a visualforce page.
The problem is that mobile pictures are always to big. Because of this Salesforce won't accept the base64 because the size is to big.
How can i resize this before uploading. For small images the functionality works perfect.
Code atm:
Javascript:
function uploadFile() { var input = document.getElementById('file-input'); var parentId = 'a0fL0000004TCDA'; 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"); att.Name = this.file.name; att.ContentType = this.file.type; att.ParentId = parentId; att.Body = (new sforce.Base64Binary(e.target.result)).toString(); var testvar = att.Body; alert('Test:' + testvar.length ); sforce.connection.create([att], { onSuccess : function(result, source) { if (result[0].getBoolean("success")) { console.log("new attachment created with id " + result[0].id); } else { console.log("failed to create attachment " + result[0]); } }, onFailure : function(error, source) { console.log("An error has occurred " + error); } }); }; reader.readAsBinaryString(f); } }HTML:
<input id="file-input" type="file" name="file"/> <input type="button" value="Add Review" style="font-size:12px;" onclick="uploadFile;"/>
Thanks in Advance!
Alternatively, you can look for any online service that does that, but it may require a subscription.