示例#1
0
        public void UploadContent(ContentUploadModel model)
        {
            if (model?.ContentCategoryEnum != ContentCategoryEnum.Image)
            {
                throw new Exception("Only image files are supported");
            }

            var contentBytes = Convert.FromBase64String(model.ContentBase64);

            File.WriteAllBytes("lastPicture.jpg", contentBytes);
        }
示例#2
0
        public async Task UploadContent(ContentUploadModel model)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                var uri = $"http://{settingsService.HostIP}:{settingsService.HostPort}/api/SmartHouse/UploadContent";

                var modelString = JsonConvert.SerializeObject(model);
                var content     = new StringContent(modelString, Encoding.UTF8, "application/json");

                var response = await client.PostAsync(uri, content);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(await response.Content.ReadAsStringAsync());
                }
            }
        }