global with sharing class UploadCantoFiles{ static final String cantolocationId='0581x000000AvymAAC'; public String url{ get; set; } public String title{ get; set; } public UploadCantoFiles() { } // empty constructor public void init() { } public String getAccessToken() { return getOauth().accessToken__c; } public String getTenant() { return getOauth(). tenant__c; } public oauthInfo__c getOauth() { return oauthInfo__c.getInstance(UserInfo.getUserId()); } @RemoteAction global static void saveOauth(String accesstoken,String tenant) { List token = [ select tenant__c,accessToken__c,uid__c from oauthInfo__c where uid__c = :UserInfo.getUserId() ]; if(token !=null&& token.size()>0) { Delete token; } oauthInfo__c cs = new oauthInfo__c (accessToken__c=accesstoken, tenant__c=tenant,uid__c= UserInfo.getUserId()); insert cs; } @RemoteAction global static void removeCache() { oauthInfo__c token = [ select tenant__c,accessToken__c,uid__c from oauthInfo__c where uid__c = :UserInfo.getUserId() ]; Delete token; } global static List getResourceFiles() { return [select id, Title, Description, FileType, Owner.Name, VersionNumber from ContentVersion Where IsLatest= true and FirstPublishLocationId = :cantoLocationId ORDER BY LastModifiedDate DESC ]; } @RemoteAction global static String saveImage(String url,String title) { Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('GET'); req.setTimeout(80000); HttpResponse res = null; res = h.send(req); string responseValue = ''; responseValue = res.getBody(); system.debug('Response Body for File: ' + responseValue); blob image = res.getBodyAsBlob(); ContentVersion cv = new ContentVersion(); cv.VersionData = image; //This is our blob cv.title = title ; cv.Description = 'file from canto'; cv.FirstPublishLocationId = cantoLocationId; //This is the library cv.TagCsv = 'Canto'; cv.PathOnClient = 'https://canto--dev2.lightning.force.com/'+title+'.jpg'; insert cv; return cv.id; } }