public void UploadAttributeFile(PAEntityBase <T> entity, string fileAttributeName, string fileName, string fileMimeType, Stream fileStream) { var orgService = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService); InitializeFileBlocksUploadRequest initRequest = new InitializeFileBlocksUploadRequest() { FileAttributeName = fileAttributeName, FileName = fileName, Target = entity.EntityRecord.ToEntityReference() }; var initResponse = (InitializeFileBlocksUploadResponse)orgService.Execute(initRequest); int perSize = 1024 * 1024 * 3; //int perSize = 100; int currentSize = perSize; byte[] buff = new byte[perSize]; List <string> blockIDs = new List <string>(); while (currentSize == perSize) { currentSize = fileStream.Read(buff, 0, perSize); if (currentSize != 0) { var blockID = Guid.NewGuid().ToString().Base64Encode(); blockIDs.Add(blockID); UploadBlockRequest uploadRequest = new UploadBlockRequest() { BlockId = blockID, FileContinuationToken = initResponse.FileContinuationToken, BlockData = buff.Take(currentSize).ToArray() }; orgService.Execute(uploadRequest); } } CommitFileBlocksUploadRequest commitRequest = new CommitFileBlocksUploadRequest() { BlockList = blockIDs.ToArray(), FileContinuationToken = initResponse.FileContinuationToken, FileName = fileName, MimeType = fileMimeType }; orgService.Execute(commitRequest); }
public void DownloadAttributeFile(PAEntityBase <T> entity, string fileAttributeName, Action <string, Stream> action) { var orgService = ContextContainer.GetValue <IOrganizationService>(ContextTypes.OrgService); InitializeFileBlocksDownloadRequest initRequest = new InitializeFileBlocksDownloadRequest() { FileAttributeName = fileAttributeName, Target = entity.EntityRecord.ToEntityReference() }; var initResponse = (InitializeFileBlocksDownloadResponse)orgService.Execute(initRequest); using (var stream = new PAFileBlocksStream(initResponse.FileContinuationToken, initResponse.FileSizeInBytes, orgService)) { action(initResponse.FileName, stream); } }
public void DeleteAttributeFileData(PAEntityBase <T> entity, string fileAttributeName) { }