public string GetHash(string hash, IFormFile file) { byte[] bytes = Array.Empty <byte>(); using (var ms = new MemoryStream()) { file.CopyToAsync(ms); bytes = ms.ToArray(); } using (SHA256 sha256Hash = SHA256.Create()) { hash = binaryObjectManager.GetHash(sha256Hash, bytes); } return(hash); }
public List <BinaryObject> UpdateAttachedFiles(UpdateQueueItemViewModel request, QueueItem queueItem) { var attachments = queueItemAttachmentRepository.Find(null, q => q.QueueItemId == request.Id)?.Items; var files = request.Files.ToList(); foreach (var attachment in attachments) { var binaryObject = binaryObjectRepository.GetOne(attachment.BinaryObjectId); //check if file with same hash and queue item id already exists foreach (var file in request.Files) { byte[] bytes = Array.Empty <byte>(); using (var ms = new MemoryStream()) { file.CopyToAsync(ms); bytes = ms.ToArray(); } string hash = string.Empty; using (SHA256 sha256Hash = SHA256.Create()) { hash = binaryObjectManager.GetHash(sha256Hash, bytes); } if (binaryObject.HashCode == hash && binaryObject.CorrelationEntityId == request.Id) { files.Remove(file); } } } //if file doesn't exist in binary objects (list of files): add binary object entity, upload file, and add queue item attachment entity var binaryObjects = AttachFiles(files, (Guid)queueItem.Id, queueItem); return(binaryObjects); }