Beispiel #1
0
        public async void Upload(FileStream stream, string fileName)
        {
            var auth = new Firebase.Auth.FirebaseAuthProvider(new Firebase.Auth.FirebaseConfig(ApiKey));
            var a    = await auth.SignInWithEmailAndPasswordAsync(AuthEmail, AuthPassword);

            // You can use CancellationTokenSource to cancel the upload midway
            var cancellation = new CancellationTokenSource();

            var task = new Firebase.Storage.FirebaseStorage(
                Bucket,
                new Firebase.Storage.FirebaseStorageOptions
            {
                AuthTokenAsyncFactory = () => Task.FromResult(a.FirebaseToken),
                ThrowOnCancel         = true // when you cansel the upload, exception is thrown, By default no exception is thrown
            })
                       .Child("images")
                       .Child(fileName)
                       .PutAsync(stream, cancellation.Token);

            try
            {
                // error during upload will be thrown when await the task
                string link = await task;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception was thrown: {0}", ex);
            }
        }
        public static async Task <String> getDoc(Stream fileStream, String fileName, String apiKey)
        {
            var auth  = new FirebaseAuthProvider(new FirebaseConfig(apiKey));
            var login = await auth.SignInAnonymouslyAsync();

            var task = new Firebase.Storage.FirebaseStorage("tayduky-d785d.appspot.com", new Firebase.Storage.FirebaseStorageOptions
            {
                AuthTokenAsyncFactory = () => Task.FromResult(login.FirebaseToken)
            }).Child("docs").Child(fileName).PutAsync(fileStream);

            return(await task);
        }
        public async Task <string> UploadVideo(FileResult video)
        {
            Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.Instance;
            var stream = await video.OpenReadAsync();

            var name = System.Guid.NewGuid() + ".mp4";
            await storage.GetReference(name).PutStream(stream);

            stream.Close();

            var url = await storage.GetReference(name).GetDownloadUrl();

            return(url.ToString());
        }
Beispiel #4
0
        public static async Task <String> getFile(Stream fileStream, String fileName)
        {
            String apiKey = "AIzaSyD4witV5uIhlnYtWPZ2ZPNfQNh9V-0_RBU";
            var    auth   = new FirebaseAuthProvider(new FirebaseConfig(apiKey));
            var    login  = await auth.SignInAnonymouslyAsync();

            var task = new Firebase.Storage.FirebaseStorage("hci-project-281007.appspot.com",
                                                            new Firebase.Storage.FirebaseStorageOptions
            {
                AuthTokenAsyncFactory = () => Task.FromResult(login.FirebaseToken)
            })
                       .Child("image")
                       .Child(fileName)
                       .PutAsync(fileStream);

            // Track progress of the upload
            task.Progress.ProgressChanged += (s, e) => Console.WriteLine($"Progress: {e.Percentage} %");
            // Await the task to wait until upload is completed and get the download url
            return(await task);
        }
 public StorageWrapper(Firebase.Storage.FirebaseStorage storage)
 {
     _storage = storage ?? throw new ArgumentNullException(nameof(storage));
 }
Beispiel #6
0
 public FirebaseStorage(FirebaseApp app)
 {
     storage = Firebase.Storage.FirebaseStorage.GetInstance(app);
 }
 public static StorageWrapper GetStorage(Firebase.Storage.FirebaseStorage storage)
 {
     return(new StorageWrapper(storage));
 }
 public static StorageWrapper GetStorage(Firebase.Storage.FirebaseStorage storage)
 {
     return(_storages.GetOrAdd(storage, key => new Lazy <StorageWrapper>(() => new StorageWrapper(key))).Value);
 }