Пример #1
0
        private async void DoApiPost()
        {
            Debug.WriteLine("in the DoApiPost");
            TextBlockResponse = "Begin Post test";

            HttpMessageHandler handler = new HttpClientHandler();
            var client = new HttpClient(handler);

            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.BaseAddress = new Uri(Settings.Default.ApiUrl);

            string fileName = Path.GetFileName(_filePickerFullyQualifiedFileName);

            var picture = new Picture
            {
                Name        = fileName,
                Description = TextBlockDescription,
                Tags        = "Image,Test"
            };

            string filename = _filePickerFullyQualifiedFileName;

            var bitmap = Image.FromFile(filename) as Bitmap;

            var content = new MultipartFormDataContent
            {
                { new StringContent(picture.Name), AddQuotes("name") },
                { new StringContent(picture.Description), AddQuotes("description") },
                { new StringContent(picture.Tags), AddQuotes("tags") },
            };

            var image = new ByteArrayContent(ImageToByteArray(bitmap));

            image.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            content.Add(image, "filename", "image.jpg");

            HttpResponseMessage response = await client.PostAsync("api/pictures", content);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                String result = await response.Content.ReadAsStringAsync();

                var newpicture = JsonConvert.DeserializeObject <Picture>(result);
                TextBlockResponse += "\n" + newpicture.Url;
                ImageSource        = newpicture.Url.ToString();
                QrCodeImage        = QrCodeUtility.GetQrCodeImage(newpicture.Url.ToString());
            }
        }
Пример #2
0
        /// <summary>
        ///     Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IDataService dataService)
        {
            _dataService = dataService;
            _dataService.GetData(
                (item, error) =>
            {
                if (error != null)
                {
                    // Report error here
                }
                //WelcomeTitle = item.Title;
            });

            ButtonCommandPost = new RelayCommand(DoApiPost);
            ButtonFileChooser = new RelayCommand(DoFileChooser);
            QrCodeImage       =
                QrCodeUtility.GetQrCodeImage("Upload an image using this test client. This QR code will point to it.");
        }