| | |
| | | @RemoteAction |
| | | public static String testAddAttachment(String attachmentName,String attachmentType, String attachmentBody,String parentId) { |
| | | String operateResult; |
| | | Attachment tmpAttachment = new Attachment(); |
| | | tmpAttachment.Name = attachmentName; |
| | | tmpAttachment.Body = EncodingUtil.base64Decode(attachmentBody); |
| | | tmpAttachment.ParentId = parentId; |
| | | tmpAttachment.ContentType = attachmentType; |
| | | // Attachment tmpAttachment = new Attachment(); |
| | | // tmpAttachment.Name = attachmentName; |
| | | // tmpAttachment.Body = EncodingUtil.base64Decode(attachmentBody); |
| | | // tmpAttachment.ParentId = parentId; |
| | | // tmpAttachment.ContentType = attachmentType; |
| | | ContentVersion version = new ContentVersion(); |
| | | version.Title = attachmentName; |
| | | version.VersionData = EncodingUtil.base64Decode(attachmentBody); |
| | | version.ContentLocation = 's'; |
| | | version.PathOnClient = attachmentName + '.' + attachmentType; |
| | | try { |
| | | insert tmpAttachment; |
| | | insert version; |
| | | version = [select Id,ContentDocumentId from ContentVersion where Id =: version.Id]; |
| | | ContentDocumentLink link = new ContentDocumentLink(); |
| | | link.ContentDocumentId = version.ContentDocumentId; |
| | | link.LinkedEntityId = parentId; |
| | | link.ShareType = 'I'; |
| | | link.Visibility = 'AllUsers'; |
| | | insert link; |
| | | operateResult = '您已上传文件成功!'; |
| | | } catch (Exception e){ |
| | | operateResult = '上传文件失败,请重试!'; |