My_Test_Repo/force-app/main/default/classes/FileUploadService.cls

64 lines
2.3 KiB
OpenEdge ABL

public with sharing class FileUploadService {
@AuraEnabled
public static String uploadFile(String base64, String filename, String recordId) {
ContentVersion cv = new ContentVersion();
cv.VersionData = EncodingUtil.base64Decode(base64);
cv.Title = filename+'FPU';
cv.PathOnClient = filename;
insert cv;
system.debug('cv data'+cv);
ContentDocumentLink cdl = new ContentDocumentLink();
cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: cv.id].ContentDocumentId;
cdl.LinkedEntityId = recordId;
cdl.ShareType = 'V';
insert cdl;
system.debug('cdl data'+cdl);
ContentVersion cvv = [SELECT Id,ContentBodyId FROM ContentVersion WHERE Id = :cv.Id];
system.debug('cvv data'+cvv);
String imageUrl= 'https://suprnova-dev-ed.develop.file.force.com/sfc/servlet.shepherd/version/renditionDownload?rendition=ORIGINAL_Jpg&versionId='+cvv.Id +'&operationContext=CHATTER&contentId='+cvv.ContentBodyId;
Friend__c c=[SELECT ProfileUrl__c FROM Friend__c WHERE Id = :recordId];
c.ProfileUrl__c=imageUrl;
update c;
return imageUrl;
}
@AuraEnabled
public static String deletefile(String Contentv, String recordid) {
try {
system.debug('@@@@@'+Contentv+'@@@@'+recordid);
List<ContentVersion> cvList = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :Contentv];
if (cvList.isEmpty()) {
throw new AuraHandledException('No ContentVersion found with the given ID');
}
ContentVersion cv = cvList[0];
List<ContentDocument> cdList = [SELECT Id FROM ContentDocument WHERE Id = :cv.ContentDocumentId];
if (cdList.isEmpty()) {
throw new AuraHandledException('No ContentDocument found with the given ID');
}
ContentDocument cd = cdList[0];
List<Friend__c> cList = [SELECT ProfileUrl__c FROM Friend__c WHERE Id = :recordid];
if (cList.isEmpty()) {
throw new AuraHandledException('No Friend__c record found with the given ID');
}
Friend__c c = cList[0];
c.ProfileUrl__c = null;
update c;
delete cd;
return 'Deletion successful';
} catch (Exception e) {
throw new AuraHandledException(e.getMessage());
}
}
}