| | |
| | | public static Id saveTheFile(Id parentId, String fileName, String base64Data, String contentType) { |
| | | base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8'); |
| | | |
| | | Attachment oAttachment = new Attachment(); |
| | | oAttachment.parentId = parentId; |
| | | // Attachment oAttachment = new Attachment(); |
| | | // oAttachment.parentId = parentId; |
| | | |
| | | oAttachment.Body = EncodingUtil.base64Decode(base64Data); |
| | | oAttachment.Name = fileName; |
| | | oAttachment.ContentType = contentType; |
| | | // oAttachment.Body = EncodingUtil.base64Decode(base64Data); |
| | | // oAttachment.Name = fileName; |
| | | // oAttachment.ContentType = contentType; |
| | | |
| | | insert oAttachment; |
| | | // insert oAttachment; |
| | | ContentVersion version = new ContentVersion(); |
| | | version.Title = fileName; |
| | | version.VersionData = EncodingUtil.base64Decode(base64Data); |
| | | version.ContentLocation = 's'; |
| | | version.PathOnClient = fileName + '.' + contentType; |
| | | insert version; |
| | | version = [select ContentDocumentId from ContentVersion where Id =: version.Id limit 1]; |
| | | ContentDocumentLink link = new ContentDocumentLink(); |
| | | link.LinkedEntityId = parentId; |
| | | link.ContentDocumentId = version.ContentDocumentId; |
| | | link.ShareType = 'I'; |
| | | link.Visibility = 'AllUsers'; |
| | | insert link; |
| | | |
| | | return oAttachment.Id; |
| | | return link.ContentDocumentId; |
| | | } |
| | | |
| | | private static void appendToFile(Id fileId, String base64Data) { |
| | | base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8'); |
| | | |
| | | Attachment a = [ |
| | | SELECT Id, Body |
| | | FROM Attachment |
| | | WHERE Id =: fileId |
| | | ]; |
| | | // Attachment a = [ |
| | | // SELECT Id, Body |
| | | // FROM Attachment |
| | | // WHERE Id =: fileId |
| | | // ]; |
| | | ContentVersion verison = [select Id,VersionData from ContentVersion where ContentDocumentId =: fileId]; |
| | | |
| | | String existingBody = EncodingUtil.base64Encode(a.Body); |
| | | // String existingBody = EncodingUtil.base64Encode(a.Body); |
| | | String existingBody = EncodingUtil.base64Encode(verison.VersionData); |
| | | |
| | | a.Body = EncodingUtil.base64Decode(existingBody + base64Data); |
| | | verison.VersionData = EncodingUtil.base64Decode(existingBody + base64Data); |
| | | |
| | | update a; |
| | | update verison; |
| | | } |
| | | |
| | | //文件删除功能 精琢技术 thh 2021-09-26 start |
| | | @AuraEnabled |
| | | public static void deleteChunk(Id AttachmentId) { |
| | | Attachment attachment = new Attachment(); |
| | | attachment.id = AttachmentId; |
| | | // Attachment attachment = new Attachment(); |
| | | // attachment.id = AttachmentId; |
| | | |
| | | delete attachment; |
| | | // delete attachment; |
| | | ContentDocument con = new ContentDocument(); |
| | | con.Id = AttachmentId; |
| | | delete con; |
| | | } |
| | | //文件删除功能 精琢技术 thh 2021-09-26 end |
| | | } |