Example #1
0
        private async void ButtonUpload_Clicked(object sender, EventArgs e)
        {
            loadingIndicator.IsRunning = true;

            if (byteData != null)
            {
                uploadedFilename = await AzureBlobContainer.UploadFileAsync(ContainerType.Image, new MemoryStream(byteData), extenstion);
            }
            loadingIndicator.IsRunning = false;
        }
Example #2
0
        public ImageFileUploader(string path)
        {
            var imageToUpload     = new Image();
            var downloadedImage   = new Image();
            var activityIndicator = new ActivityIndicator();
            var extension         = Path.GetExtension(path);
            var downloadButton    = new Button {
                Text = "Download Image", IsEnabled = false
            };

            downloadButton.Clicked += async(sender, e) =>
            {
                if (!string.IsNullOrWhiteSpace(uploadedFilename))
                {
                    activityIndicator.IsRunning = true;

                    var imageData = await AzureBlobContainer.GetFileAsync(ContainerType.Image, uploadedFilename);

                    downloadedImage.Source = ImageSource.FromStream(() => new MemoryStream(imageData));

                    activityIndicator.IsRunning = false;
                }
            };

            var uploadButton = new Button {
                Text = "Upload Image"
            };

            uploadButton.Clicked += async(sender, e) =>
            {
                activityIndicator.IsRunning = true;

                uploadedFilename = await AzureBlobContainer.UploadFileAsync(ContainerType.Image, new MemoryStream(byteData), extension);

                uploadButton.IsEnabled      = false;
                downloadButton.IsEnabled    = true;
                activityIndicator.IsRunning = false;
            };

#if __IOS__
            byteData = Convert.ToByteArray("FileUploader.iOS.waterfront.jpg");
#endif
#if __ANDROID__
            byteData = Convert.ToByteArray(path);
#endif
#if WINDOWS_UWP
            byteData = Convert.ToByteArray("FileUploader.UWP.waterfront.jpg");
#endif

            imageToUpload.Source = ImageSource.FromStream(() => new MemoryStream(byteData));
        }
Example #3
0
        public App()
        {
            MobileCenter.Start(typeof(Analytics), typeof(Crashes));
            this.BindingContext = this;
            Button buttonPickImage = new Button {
                Text = "Pick a Photo"
            };
            Button buttonUpload = new Button {
                Text = "Upload ", IsEnabled = false
            };
            Button buttonRefresh = new Button {
                Text = "Refresh ", IsEnabled = false
            };

            buttonRefresh.Clicked   += ButtonRefresh_Clicked;
            buttonUpload.Clicked    += ButtonUpload_Clicked;
            buttonPickImage.Clicked += async(sender, args) =>
            {
                buttonRefresh.IsEnabled             = false;
                Application.Current.MainPage.IsBusy = true;

                loadingIndicator.IsRunning = true;
                await CrossMedia.Current.Initialize();

                var f = await Plugin.Media.CrossMedia.Current.PickPhotoAsync();

                if (f == null)
                {
                    return;
                }
                path                   = f.Path;
                extenstion             = System.IO.Path.GetFileName(f.Path);
                buttonUpload.IsEnabled = true;
                //image.Source = ImageSource.FromStream(() =>
                //{
                //    var stream = f.GetStream();
                //    // f.Dispose();
                //    return stream;
                //});
                //image.HeightRequest = 10.0;
                byteData = ba(f);
                if (byteData != null)
                {
                    uploadedFilename = await AzureBlobContainer.UploadFileAsync(ContainerType.Image, new MemoryStream(byteData), extenstion);
                }

                Thread.Sleep(9000);
                lbl.Text = $"File Uploaded {path } ";
                buttonRefresh.IsEnabled             = true;
                loadingIndicator.IsRunning          = false;
                Application.Current.MainPage.IsBusy = false;
            };

            loadingIndicator = new ActivityIndicator
            {
                Color           = Color.White,
                VerticalOptions = LayoutOptions.Center,
                WidthRequest    = 20,
                HeightRequest   = 20,
                IsEnabled       = true,
                IsVisible       = true,
                IsRunning       = true
            };
            //loadingIndicator.IsEnabled = true;
            loadingIndicator.BindingContext = this;
            loadingIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy", BindingMode.OneWay);

            var overlay = new AbsoluteLayout();

            AbsoluteLayout.SetLayoutFlags(loadingIndicator, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(loadingIndicator, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));

            overlay.Children.Add(loadingIndicator);


            searchBar = new SearchBar
            {
                Placeholder = "Enter search term",
                ,
                SearchCommand = new Command(() => { lbl.Text = "Result: " + searchBar.Text + " is what you asked for."; })
            };
            StackLayout content = new StackLayout
            {
                VerticalOptions = LayoutOptions.Start,
                Padding         = new Thickness(10, Xamarin.Forms.Device.OnPlatform(20, 0, 0), 10, 5),
                Children        =
                {
                    searchBar,
                    buttonPickImage,
                    //image,
                    //buttonUpload,
                    buttonRefresh,
                    lbl
                }
            };


            // The root page of your application
            MainPage = new ContentPage
            {
                Content = content
            };
        }