Пример #1
0
        public async Task GetImageWithBytesAsync_Test()
        {
            SaveImageByUrlRequest saveRequest = new SaveImageByUrlRequest()
            {
                ImageUrl = "https://www.baidu.com/img/bd_logo1.png?where=super"
            };

            SaveImageResponse saveResponse = await _imageAppService.SaveImageByUrlAsync(saveRequest);

            GetImageRequest getRequest = new GetImageRequest()
            {
                BucketName = saveResponse.BucketName,
                ImageName  = saveResponse.ImageName
            };

            GetImageWithBytesResponse getResponse = await _imageAppService.GetImageWithBytesAsync(getRequest);

            using (MD5 md5Hash = MD5.Create())
            {
                byte[] md5Bytes = md5Hash.ComputeHash(getResponse.ImageData);

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < md5Bytes.Length; i++)
                {
                    sb.Append(md5Bytes[i].ToString("X2"));
                }

                sb.ToString().ShouldBe("B15C113AEDDBEB606D938010B88CF8E6");
            }
        }
Пример #2
0
        public async Task SaveImageByUrlAsync_Test()
        {
            SaveImageByUrlRequest request = new SaveImageByUrlRequest()
            {
                ImageUrl = "https://www.baidu.com/img/bd_logo1.png?where=super"
            };

            SaveImageResponse response = await _imageAppService.SaveImageByUrlAsync(request);

            response.Location.ShouldBe("us-east-1");
            response.BucketName.ShouldBe(DateTime.Today.ToString("yyyy-MM-dd"));
            response.ImageName.ShouldBe("B15C113AEDDBEB606D938010B88CF8E6");
        }
Пример #3
0
 public async Task <SaveImageResponse> SaveImageByUrlAsync(SaveImageByUrlRequest request)
 {
     try
     {
         var client = _httpClientFactory.CreateClient();
         using (var stream = await client.GetStreamAsync(request.ImageUrl))
         {
             return(await SaveImageBytes(stream.GetAllBytes()));
         }
     }
     catch (Exception exception)
     {
         //SentrySdk.CaptureException(exception);
         throw;
     }
 }
Пример #4
0
        public async Task DownloadImageAsync_Test()
        {
            SaveImageByUrlRequest saveRequest = new SaveImageByUrlRequest()
            {
                ImageUrl = "https://www.baidu.com/img/bd_logo1.png?where=super"
            };

            SaveImageResponse saveResponse = await _imageAppService.SaveImageByUrlAsync(saveRequest);

            DownloadImageRequest downloadRequest = new DownloadImageRequest()
            {
                BucketName = saveResponse.BucketName,
                ImageName  = saveResponse.ImageName,
                ImageType  = "png"
            };

            FileStreamResult getResponse = await _imageAppService.DownloadImageAsync(downloadRequest);

            getResponse.FileStream.Length.ShouldBe(7877);
        }
Пример #5
0
        public async Task GetImageStatusAsync_Test()
        {
            SaveImageByUrlRequest saveRequest = new SaveImageByUrlRequest()
            {
                ImageUrl = "https://www.baidu.com/img/bd_logo1.png?where=super"
            };

            SaveImageResponse saveResponse = await _imageAppService.SaveImageByUrlAsync(saveRequest);

            GetImageRequest getRequest = new GetImageRequest()
            {
                BucketName = saveResponse.BucketName,
                ImageName  = saveResponse.ImageName
            };

            GetImageStatusResponse getResponse = await _imageAppService.GetImageStatusAsync(getRequest);

            getResponse.ImageName.ShouldBe("B15C113AEDDBEB606D938010B88CF8E6");
            getResponse.Size.ShouldBe(7877);
        }