Esempio n. 1
0
        public async Task UploadImage(ImageInfoParams imageInfoParam, CancellationToken cancellationToken = default)
        {
            try
            {
                this.logger.LogInformation("Start upload image on cloud ...");

                if (!await this.SaveThumbnailImage(imageInfoParam))
                {
                    this.logger.LogError($"Has error when upload thumbnail file. ImageId:{imageInfoParam.ImageId}");
                    return;
                }

                if (!await this.SaveOriginalImage(imageInfoParam))
                {
                    this.logger.LogError($"Has error when upload original file. ImageId:{imageInfoParam.ImageId}");
                    return;
                }

                this.DeleteLocalFiles(Path.GetDirectoryName(imageInfoParam.ImagePath));

                this.logger.LogInformation($"Images for ImageId:{imageInfoParam.ImageId} has been uploaded!");
            }
            catch (Exception e)
            {
                this.logger.LogError(e, $"Has error when upload files. ImageId:{imageInfoParam.ImageId}");
            }
        }
Esempio n. 2
0
        private async Task <bool> SaveThumbnailImage(ImageInfoParams imageInfoParam)
        {
            StoreFileInfo remoteImage = await this.GenerateThumbnailImage(imageInfoParam.ImagePath);

            if (!remoteImage.BoolResult)
            {
                return(false);
            }

            TempCloudImage newCloudImage = new TempCloudImage()
            {
                ImageId   = imageInfoParam.ImageId,
                FileId    = remoteImage.FileId,
                ImageUrl  = remoteImage.FileAddress,
                ImageType = (int)ImageType.Thumbnail,
            };

            await this.tempCloudImage.CreateAsync(newCloudImage);

            return(true);
        }