Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get picture (thumb) local path
        /// </summary>
        /// <param name="thumbFileName">Filename</param>
        /// <returns>Local picture thumb path</returns>
        public virtual string GetThumbLocalPath(string thumbFileName)
        {
            var thumbsDirectoryPath = _fileProvider.GetAbsolutePath(AQMediaDefaults.ImageThumbsPath);

            if (_mediaSettings.MultipleThumbDirectories)
            {
                //get the first two letters of the file name
                var fileNameWithoutExtension = _fileProvider.GetFileNameWithoutExtension(thumbFileName);
                if (fileNameWithoutExtension != null && fileNameWithoutExtension.Length > AQMediaDefaults.MultipleThumbDirectoriesLength)
                {
                    var subDirectoryName = fileNameWithoutExtension.Substring(0, AQMediaDefaults.MultipleThumbDirectoriesLength);
                    thumbsDirectoryPath = _fileProvider.GetAbsolutePath(AQMediaDefaults.ImageThumbsPath, subDirectoryName);
                    _fileProvider.CreateDirectory(thumbsDirectoryPath);
                }
            }

            var thumbFilePath = _fileProvider.Combine(thumbsDirectoryPath, thumbFileName);

            return(thumbFilePath);
        }