Beispiel #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);
        }
Beispiel #2
0
        public virtual string GetDefaultPictureUrl(int targetSize = 0,
                                                   PictureType defaultPictureType = PictureType.Entity,
                                                   string storeLocation           = null)
        {
            string defaultImageFileName;

            switch (defaultPictureType)
            {
            case PictureType.Avatar:
                defaultImageFileName = "default-avatar.jpg";
                break;

            case PictureType.Entity:
            default:
                defaultImageFileName = "default-image.png";
                break;
            }

            var filePath = GetPictureLocalPath(defaultImageFileName);

            if (!_fileProvider.FileExists(filePath))
            {
                return(string.Empty);
            }

            if (targetSize == 0)
            {
                var url = (!string.IsNullOrEmpty(storeLocation)
                                 ? storeLocation
                                 : _webHelper.GetStoreLocation())
                          + "contents/images/" + defaultImageFileName;
                return(url);
            }
            else
            {
                var fileExtension = _fileProvider.GetFileExtension(filePath);
                var thumbFileName = $"{_fileProvider.GetFileNameWithoutExtension(filePath)}_{targetSize}{fileExtension}";
                var thumbFilePath = GetThumbLocalPath(thumbFileName);
                if (!GeneratedThumbExists(thumbFilePath, thumbFileName))
                {
                    using (var image = Image.Load(filePath, out var imageFormat))
                    {
                        image.Mutate(imageProcess => imageProcess.Resize(new ResizeOptions
                        {
                            Mode = ResizeMode.Max,
                            Size = CalculateDimensions(image.Size(), targetSize)
                        }));
                        var pictureBinary = EncodeImage(image, imageFormat);
                        SaveThumb(thumbFilePath, thumbFileName, imageFormat.DefaultMimeType, pictureBinary);
                    }
                }

                var url = GetThumbUrl(thumbFileName, storeLocation);
                return(url);
            }
        }