Exemplo n.º 1
0
        public async Task <FileInfoDTO> GetFileInfo(SubAttachmentData image, string postId)
        {
            using (var imageResponse = await _facebookClient.GetImage(image.Media.Image.Src))
            {
                using (var imageStream = await imageResponse.Content.ReadAsStreamAsync())
                {
                    var mediaType = imageResponse.Content.Headers.ContentType.MediaType.Split('/');
                    if (mediaType.FirstOrDefault() == "image")
                    {
                        var fileRequest = new CreateFileRequest
                        {
                            Name        = "FacebookImg_" + postId + "." + mediaType.LastOrDefault(),
                            ContentType = imageResponse.Content.Headers.ContentType.MediaType,
                            SizeKB      = Convert.ToInt32(imageResponse.Content.Headers.ContentLength)
                        };

                        return(await _fileService.CreateAsync(fileRequest, imageStream));
                    }
                    return(null);
                }
            }
        }