You need to sign in to do that
Don't have an account?
Raffus
How to write a test method content document
@AuraEnabled
public static FileInfoWrapper createPublicUrl(String fileData) {
try {
FileInfoWrapper file = (FileInfoWrapper)JSON.deserialize(fileData, FileInfoWrapper.class);
if (String.isNotBlank(file.base64Data)) {
ContentVersion cv = new ContentVersion();
cv.ContentLocation = 'S';
cv.PathOnClient = file.fileName;
cv.VersionData = EncodingUtil.base64Decode(file.base64Data);
cv.Title = file.fileName;
insert cv;
ContentDistribution cd = new ContentDistribution();
cd.Name = file.fileName;
cd.ContentVersionId = cv.Id;
cd.PreferencesAllowViewInBrowser = true;
cd.PreferencesLinkLatestVersion = true;
cd.PreferencesNotifyOnVisit = false;
cd.PreferencesPasswordRequired = false;
cd.PreferencesAllowOriginalDownload = true;
insert cd;
cd = [SELECT Id, ContentVersionId, ContentDownloadUrl FROM ContentDistribution WHERE Id = :cd.Id];
file.publicUrl = cd.ContentDownloadUrl;
file.contentDistributionId = cd.Id;
file.contentVersionId = cd.ContentVersionId;
return file;
}
else {
return file;
}
}
public static FileInfoWrapper createPublicUrl(String fileData) {
try {
FileInfoWrapper file = (FileInfoWrapper)JSON.deserialize(fileData, FileInfoWrapper.class);
if (String.isNotBlank(file.base64Data)) {
ContentVersion cv = new ContentVersion();
cv.ContentLocation = 'S';
cv.PathOnClient = file.fileName;
cv.VersionData = EncodingUtil.base64Decode(file.base64Data);
cv.Title = file.fileName;
insert cv;
ContentDistribution cd = new ContentDistribution();
cd.Name = file.fileName;
cd.ContentVersionId = cv.Id;
cd.PreferencesAllowViewInBrowser = true;
cd.PreferencesLinkLatestVersion = true;
cd.PreferencesNotifyOnVisit = false;
cd.PreferencesPasswordRequired = false;
cd.PreferencesAllowOriginalDownload = true;
insert cd;
cd = [SELECT Id, ContentVersionId, ContentDownloadUrl FROM ContentDistribution WHERE Id = :cd.Id];
file.publicUrl = cd.ContentDownloadUrl;
file.contentDistributionId = cd.Id;
file.contentVersionId = cd.ContentVersionId;
return file;
}
else {
return file;
}
}
Can you share the line where you are getting the error. Can you try this and check.
Thanks,
All Answers
Did you try just calling the method with string data.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Can you share the line where you are getting the error. Can you try this and check.
Thanks,