Ejemplo n.º 1
0
        /// <summary>
        /// Uploads the specified file bytes.
        /// </summary>
        /// <param name="fileBytes">The file bytes.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="attachmentId">The attachment identifier.</param>
        /// <param name="fileDetails">The file details.</param>
        /// <returns></returns>
        public string Upload(Stream fileBytes, string fileName, int attachmentId, IFormFile fileDetails)
        {
            string signedURL = string.Empty;

            try
            {
                var UploadResult = m_UploadAttachments.Upload(fileBytes, fileName, attachmentId);

                if (UploadResult == HttpStatusCode.OK.ToString())
                {
                    var FileS3Url = m_UploadAttachments.GetSignedURL(fileName, attachmentId);

                    var entity = new Files()
                    {
                        Date         = DateTime.Now,
                        Status       = 1,
                        AttachmentId = attachmentId,
                        FileSize     = (Int32)fileDetails.Length,
                        FileType     = fileDetails.ContentType,
                        FileName     = fileDetails.FileName,
                        FileURL      = FileS3Url
                    };
                    this.m_FileRepository.Add(entity);
                    return("Success");
                }
                return(UploadResult);
            }
            catch (Exception ex)
            {
                var message = string.Format("{0} {1} {2}", ex.InnerException == null ? ex.Message : ex.InnerException.Message, Environment.NewLine, ex.StackTrace);
                throw new Exception(message);
            }
        }