Example #1
0
        private async Task <int> UploadFileStreamFromTempFolder(string fileName, long postId)
        {
            var(fileByte, filePath, orignalFileName) = _fileStreamService.GetTempFile(fileName, CommonConstant.FILE_TEMP_FOLDER_POST);
            if (fileByte == null)
            {
                return(0);
            }
            string base64Str = Convert.ToBase64String(fileByte);
            FileDataUploadRequestModel fileUpdateModel = new FileDataUploadRequestModel();

            fileUpdateModel.FileTypeFid   = (int)FileTypeEnum.Image;
            fileUpdateModel.FolderId      = Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(postId.ToString()));
            fileUpdateModel.DomainId      = CommonConstant.FILE_STREAM_CMS_DOMAIN;
            fileUpdateModel.FileName      = _aQFileProvider.GetFileNameWithoutExtension(orignalFileName);
            fileUpdateModel.FileExtention = _aQFileProvider.GetFileExtension(orignalFileName);
            fileUpdateModel.FileData      = base64Str;
            var res = await _fileStreamService.UploadFileData(fileUpdateModel);

            if (res != null)
            {
                int fileId = res.ResponseData.FileId;
                if (fileId > 0)
                {
                    _fileStreamService.DeleteFileTemp(fileName, CommonConstant.FILE_TEMP_FOLDER_POST);
                }
                return(fileId);
            }
            return(0);
        }
Example #2
0
        public async Task <IActionResult> UploadImage(IFormFile file)
        {
            byte[]       CoverImageBytes = null;
            string       s      = string.Empty;
            BinaryReader reader = new BinaryReader(file.OpenReadStream());

            CoverImageBytes = reader.ReadBytes((int)file.Length);
            s = Convert.ToBase64String(CoverImageBytes);
            FileDataUploadRequestModel fileUpdateModel = new FileDataUploadRequestModel();

            fileUpdateModel.FileTypeFid   = (int)FileTypeEnum.Image;
            fileUpdateModel.FolderId      = CommonConstant.POST_IMAGE_FOLDER;
            fileUpdateModel.DomainId      = CommonConstant.FILE_STREAM_CMS_DOMAIN;
            fileUpdateModel.FileName      = file.FileName.Split('.')[0];
            fileUpdateModel.FileExtention = '.' + file.FileName.Split('.')[1];
            fileUpdateModel.FileData      = s;

            var res = await _fileStreamService.UploadFileData(fileUpdateModel);

            if (res != null)
            {
                var fileId = res.ResponseData.FileId;
                var url    = await _fileStreamService.GetFileById(fileId, ThumbRatioEnum.full);

                var result = new Tuple <int, string>(fileId, url);
                return(Ok(result));
            }

            return(BadRequest());
        }