예제 #1
0
        public async Task <IActionResult> Download(string id)
        {
            var file = await cdn.DownloadAsync(ObjectId.Parse(id));

            string contentType = file.FileInfo.Metadata
                                 .FirstOrDefault(k => k.Name == "contentType")
                                 .Value
                                 .ToString();

            return(File(file, contentType, file.FileInfo.Filename));
        }
예제 #2
0
        public void IngestAttachment(string id)
        {
            ObjectId fileId;

            if (ObjectId.TryParse(id, out fileId))
            {
                DocumentModel model = null;

                using (var stream = cdnService.DownloadAsync(fileId).Result)
                {
                    byte[] buffer = new byte[stream.Length];
                    stream.Read(buffer, 0, buffer.Length);
                    string data        = String.Empty;
                    string contentType = stream.FileInfo.Metadata
                                         .FirstOrDefault(k => k.Name == "contentType")
                                         .Value
                                         .ToString()
                                         .ToLower();

                    if (contentType.Contains("image"))
                    {
                        data = GetTextFromOcr(id, buffer);
                    }
                    else
                    {
                        data = Convert.ToBase64String(buffer);
                    }

                    string downloadUrl = config.GetValue <string>("DownloadUrl");

                    model = new DocumentModel()
                    {
                        Content  = data,
                        FileName = stream.FileInfo.Filename,
                        Id       = id,
                        Url      = downloadUrl + id
                    };
                }

                SendToElasticSearch(model);
            }
            else
            {
                throw new ArgumentException("Invalid cdn id");
            }
        }