[SalesForce] File Upload using Angular FileUpload

I'm trying to Upload an Image to create a Document using Angular File Upload (https://github.com/danialfarid/ng-file-upload)

From this link : Upload functionality in visualforce page I found RemoteAction method, but I'm not sure how to get the ContentOfFile in base64 and also, I was wondering if we can use AngularFileUpload to upload the image which gives support to non-html5 browsers too.

Thanks
Surya

Best Answer

Apex code for saving the chunks of file.

​public static String upload(String folderId, String documentId, String fileName, String base64BlobValue) {
        if(documentId == '' || documentId == null) {
            Document document = new Document(Name=fileName, FolderId=folderId, Body=EncodingUtil.Base64Decode(base64BlobValue), IsPublic=true);
            insert document;

            return document.Id;

        } else {

            Document document = [select Id, Body from Document where Id = :documentId];
            update new Document(Id = documentId, Body = EncodingUtil.Base64Decode(EncodingUtil.Base64Encode(document.Body) + base64BlobValue));

            return documentId;
        }
    }
Related Topic