You need to sign in to do that
Don't have an account?

Copy Content document into an Attachment
Hi - I'm trying to copy a file in a Content library into an attachment of a Contract record as I can't give the Account Owner access to a group folder in Content.
The document in Content is encypted. I've used the attached code to do the migration. If I have an unecrypted file it works fine. The encrypted files are now corrupted when they are copied into attachments. If I manually download from content and upload the encrypted files into attachments they are fine.
Any ideas on what may be changing the file structure that corrupts the encrypted files? I assume that the transfer would copy a byte for byte copy of the document?
Thanks
The document in Content is encypted. I've used the attached code to do the migration. If I have an unecrypted file it works fine. The encrypted files are now corrupted when they are copied into attachments. If I manually download from content and upload the encrypted files into attachments they are fine.
Any ideas on what may be changing the file structure that corrupts the encrypted files? I assume that the transfer would copy a byte for byte copy of the document?
Thanks
Public Pagereference Migrate() { List<contentVersion> ContentDocs = [select id,VersionData,GNS_Partner__c,Implementation_Ref__c,MFR_Ref__c,Migrated__c,Title,description,pathonclient,ownerid,contentsize from contentversion where islatest=true and Migrated__c=false and contentsize <5000001 and GNS_partner__c=:system.currentPageReference().getparameters().get('id')]; List<attachment> NewAtt = new list<attachment> (); If(ContentDocs.size()>0){ String Descrpt; For(ContentVersion c: ContentDocs){ if(c.description !=null){Descrpt = c.description;} else {descrpt = 'Executed Contract = Voltage Encrypted';} String VerData = encodingUtil.base64Encode(c.versiondata); NewAtt.add(new Attachment(ParentId=c.Implementation_Ref__c,body=EncodingUtil.base64Decode(VerData),name=c.title,description=c.description, ownerid=c.ownerid,contenttype='application/pdf')); c.Migrated__c=true; } // Update content as migrated and insert new Attachments to IMP update ContentDocs; insert NewAtt; return null; } return null;
Hope this helps !!