/// <summary> /// Init the ModelUploader /// </summary> /// <param name="targetURL">storage URL</param> /// <param name="targetDBURL">DB URL</param> public VRMUploader(string targetURL, string targetDBURL) { FirebaseApp.DefaultInstance.SetEditorDatabaseUrl(targetDBURL); DB_ref = FirebaseDatabase.DefaultInstance.RootReference; Storage = FirebaseStorage.GetInstance(targetURL); Storage_ref = Storage.GetReferenceFromUrl(targetURL); }
// Start is called before the first frame update void Start() { // When the app starts, check to make sure that we have // the required dependencies to use Firebase, and if not, // add them if possible. FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => { dependencyStatus = task.Result; if (dependencyStatus == DependencyStatus.Available) { InitializeFirebase(); } else { Debug.LogError( "Could not resolve all Firebase dependencies: " + dependencyStatus); } }); //LogEvent("testEvent",Time.time, 0); csvPath = Application.persistentDataPath + "/Analytics/" + PlayerPrefs.GetString("PlayerID", "unknown") + "/Loom.csv"; CreateNewHeader(); PlayerPrefs.SetInt("LoomSC", PlayerPrefs.GetInt("LoomSC") + 1); storage = FirebaseStorage.GetInstance("gs://loomunity-c1269.appspot.com"); }
private void OnEnable() { bool isEditor = false; #if UNITY_EDITOR isEditor = true; #endif if (isEditor) { FirebaseApp firebaseApp = FirebaseApp.Create( FirebaseApp.DefaultInstance.Options, "FIREBASE_EDITOR"); firebaseApp.SetEditorDatabaseUrl("https://artie-data.firebaseio.com/"); FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => { if (task.Result == DependencyStatus.Available) { _dbReference = FirebaseDatabase.GetInstance(firebaseApp).RootReference; _storage = FirebaseStorage.GetInstance(firebaseApp); _auth = FirebaseAuth.GetAuth(firebaseApp); _phoneProvider = PhoneAuthProvider.GetInstance(_auth); _functions = FirebaseFunctions.DefaultInstance; if (localServices.Value) { _functions.UseFunctionsEmulator("http://localhost:5001"); } // Listener for authentications changes _auth.StateChanged += this.AuthStateChanged; AuthStateChanged(this, null); } else { Debug.LogError("Could not resolve all Firebase dependencies: " + task.Result); Console.WriteLine("Could not resolve all Firebase dependencies: " + task.Result); // Listener for authentications changes _auth.StateChanged += this.AuthStateChanged; AuthStateChanged(this, null); } }); } else { FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://artie-data.firebaseio.com/"); _dbReference = FirebaseDatabase.DefaultInstance.RootReference; _storage = FirebaseStorage.DefaultInstance; _functions = Firebase.Functions.FirebaseFunctions.DefaultInstance; _auth = FirebaseAuth.DefaultInstance; _phoneProvider = PhoneAuthProvider.GetInstance(_auth); // Listener for authentications changes _auth.StateChanged += this.AuthStateChanged; AuthStateChanged(this, null); } }
/// <summary> /// Init the ModelUploader /// </summary> /// <param name="targetURL">storage URL</param> /// <param name="targetDBURL">DB URL</param> /// <param name="user">Authenticated user data</param> public Live2DUploader(string targetURL, string targetDBURL, FirebaseUser user) { FirebaseApp.DefaultInstance.SetEditorDatabaseUrl(targetDBURL); DB_ref = FirebaseDatabase.DefaultInstance.RootReference; Storage = FirebaseStorage.GetInstance(targetURL); Storage_ref = Storage.GetReferenceFromUrl(targetURL); CurrentUser = user; }
public static void InitializeFirebaseStorage() { storage = FirebaseStorage.GetInstance(firebaseApp); baseStorageRef = storage.GetReferenceFromUrl(GlobalVariables.firebaseStorageURL); robotImageStorageRef = storage.GetReferenceFromUrl(GlobalVariables.firebaseStorageURL + GlobalVariables.regionalPointer + "/Robot Images/"); robotImageStorageRefOld = robotImageStorageRef.Child("Old"); }
public async Task <string> GetAnImageUrlFromServer(string fileURL, string fileNameWithOutExtension = "") { string response = ""; try { var firebaseStorageReference = FirebaseStorage.GetInstance(FirebaseAppInstance).Reference; #region multiple ways to get firebase instance /* * // Create a storage reference from our app * StorageReference storageRef = storage.getReference(); * * // Create a reference with an initial file path and name * StorageReference pathReference = storageRef.child("images/stars.jpg"); * * // Create a reference to a file from a Google Cloud Storage URI * StorageReference gsReference = storage.getReferenceFromUrl("gs://bucket/images/stars.jpg"); * * // Create a reference from an HTTPS URL * // Note that in the URL, characters are URL escaped! * StorageReference httpsReference = storage.getReferenceFromUrl("https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg"); */ #endregion StorageReference storageFilesReference; storageFilesReference = firebaseStorageReference.Child(fileURL); var fileURl = storageFilesReference.DownloadUrl.AddOnCompleteListener(this).AddOnFailureListener(this).AddOnSuccessListener(this); #region both works /* * var fileBytes = storageFilesReference.GetBytes(1024 * 1024). * AddOnCompleteListener(new OnCompleteListener()). * AddOnFailureListener(new OnFailureListener()). * AddOnSuccessListener(new OnSuccessListener()); * var fileBytes = storageFilesReference.GetBytes(1024 * 1024). * AddOnCompleteListener(this). * AddOnFailureListener(this). * AddOnSuccessListener(this); */ //var fileStream = storageFilesReference.Stream; //var rere = storageFilesReference.Path; //var cfgfgf = storageFilesReference.Root.Path; //var trtf = storageFilesReference.DownloadUrl.AddOnCompleteListener(this).AddOnFailureListener(this).AddOnSuccessListener(this); #endregion } catch (System.Exception ex) { var msg = ex.Message + "\n" + ex.StackTrace; System.Diagnostics.Debug.WriteLine(msg); } return(response); }
public async Task <string> GetAllImageUrlsFromServer() { string response = ""; /* * try * { * Firebase.FirebaseApp fireBaseApp = Firebase.FirebaseApp.Instance; * FirebaseStorage storageImage = FirebaseStorage.GetInstance(fireBaseApp, "gs://mytestfirebproj.appspot.com"); * //storageImage.Reference.Child() * ////Firebase.FirebaseApp fireBaseApp = Firebase.FirebaseApp.Instance; * ////FirebaseStorage storage = FirebaseStorage.GetInstance(fireBaseApp); * //var stroageImage = await new FirebaseStorage("xamarinfirebase-d3352.appspot.com") * //.Child("XamarinMonkeys") * //.Child("image.jpg") * //.PutAsync(imageStream); * //string imgurl = stroageImage; * //return imgurl; * } * catch(Exception ex) * { * var msg = ex.Message + "\n" + ex.StackTrace; * System.Diagnostics.Debug.WriteLine(msg); * } */ try { AndroidConversionService androidConversionService = new AndroidConversionService(); var streamResponse = await androidConversionService.GetStreamFromLocalFileURL(""); Firebase.FirebaseApp fireBaseApp = Firebase.FirebaseApp.Instance; //FirebaseStorage storageImage = FirebaseStorage.GetInstance(fireBaseApp, "gs://mytestfirebproj.appspot.com"); var storageImage = FirebaseStorage.GetInstance(fireBaseApp, FirebaseAppInstance).Reference.Child("FireBaseTestImageOne"); //storageImage.Reference.Child() ////Firebase.FirebaseApp fireBaseApp = Firebase.FirebaseApp.Instance; ////FirebaseStorage storage = FirebaseStorage.GetInstance(fireBaseApp); //var stroageImage = await new FirebaseStorage("xamarinfirebase-d3352.appspot.com") //.Child("XamarinMonkeys") //.Child("image.jpg") //.PutAsync(imageStream); //string imgurl = stroageImage; //return imgurl; } catch (System.Exception ex) { var msg = ex.Message + "\n" + ex.StackTrace; System.Diagnostics.Debug.WriteLine(msg); } return(response); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.activity_profile); //Setup firebase and firestore app = FirebaseApp.Instance; auth = FirebaseAuth.GetInstance(app); db = FirebaseFirestore.GetInstance(app); storage = FirebaseStorage.GetInstance(app); var name = Global.FName == string.Empty ? auth.CurrentUser.Email : Global.FName + " " + Global.LName; //ListView listView = FindViewById <ListView>(Resource.Id.profile_listview); List <ListItem> listData = new List <ListItem> { new ListItem { Heading = "NAME", SubHeading = name }, new ListItem { Heading = "EMAIL", SubHeading = auth.CurrentUser.Email }, new ListItem { Heading = "PHONE", SubHeading = Global.Phone == string.Empty ? "" : Global.Phone }, new ListItem { Heading = "ACCOUNT", SubHeading = Global.UserType == string.Empty ? "Customer" : Global.UserType } }; listView.Adapter = new ListAdapter(this, listData); listView.AddFooterView(new View(this)); displayName = FindViewById <TextView>(Resource.Id.profile_name); displayName.Text = name; profilePic = FindViewById <ImageView>(Resource.Id.profile_pic); Picasso.Get().LoggingEnabled = true; Picasso.Get().Load(new File(Global.PhotoUrl)).Placeholder(Resource.Drawable.female_user_256) .Error(Resource.Drawable.female_user_256) .Into(profilePic); profilePic.Click += ProfilePic_Click; }
// Retrieve a storage reference from the user specified path. protected StorageReference GetStorageReference() { // If this is an absolute path including a bucket create a storage instance. if (storageLocation.StartsWith("gs://") || storageLocation.StartsWith("http://") || storageLocation.StartsWith("https://")) { var storageUri = new Uri(storageLocation); var firebaseStorage = FirebaseStorage.GetInstance( String.Format("{0}://{1}", storageUri.Scheme, storageUri.Host)); return(firebaseStorage.GetReferenceFromUrl(storageLocation)); } // When using relative paths use the default storage instance which uses the bucket supplied // on creation of FirebaseApp. return(FirebaseStorage.DefaultInstance.GetReference(storageLocation)); }
public async Task <string> GetAllImageUrlsFromServer(string fileURL, string fileNameWithOutExtension = "") { string response = ""; try { var firebaseStorageReference = FirebaseStorage.GetInstance(FirebaseAppInstance).Reference; StorageReference storageFilesReference; storageFilesReference = firebaseStorageReference.Child(fileURL); var fileURl = storageFilesReference.DownloadUrl.AddOnCompleteListener(this).AddOnFailureListener(this).AddOnSuccessListener(this); } catch (System.Exception ex) { var msg = ex.Message + "\n" + ex.StackTrace; System.Diagnostics.Debug.WriteLine(msg); } return(response); }
public void Initialize(Action onSuccess = null, Action <IResultBase> onFault = null) { #if NRED_FIREBASE_STORAGE_UTIL if (isLoaded) { onFault.SafeCall(new Result { ok = false, errorCode = FirebaseUtil.ErrorCode.ALREADY_LOADED }); return; } if (buckets == null) { buckets = new List <FirebaseStorage>(8); } else { buckets.Clear(); } try { storage = FirebaseStorage.DefaultInstance; if (bucketsPath.IsAvailable()) { for (int i = 0; i < bucketsPath.Length; i++) { buckets.Add(FirebaseStorage.GetInstance(bucketsPath[i])); } } isLoaded = true; onSuccess.SafeCall(); } catch (System.Exception e) { onFault.SafeCall(new Result { ok = false, errorCode = FirebaseUtil.ErrorCode.INIT_EXCEPTION }); } #endif }
private void CreatePlayerRecordFile() { string fileName = this.GenerateRecordFileName(); while (File.Exists(fileName)) { this.round++; fileName = this.GenerateRecordFileName(); } string json = JsonUtility.ToJson(this); Directory.CreateDirectory(@"Records/" + this.bossName); System.IO.File.WriteAllText(fileName, json); FirebaseApp app = FirebaseApp.Create(); FirebaseStorage storage = FirebaseStorage.GetInstance(CLOUD_STORAGE_URL); this.storage_ref = storage.GetReferenceFromUrl(CLOUD_STORAGE_URL); StorageReference record_ref = this.storage_ref.Child(fileName); record_ref.PutBytesAsync(Encoding.UTF8.GetBytes(json)) .ContinueWith(task => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); // Uh-oh, an error occurred! } else { // Metadata contains file metadata such as size, content-type, and download URL. Firebase.Storage.StorageMetadata metadata = task.Result; string download_url = metadata.DownloadUrl.ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_url); this.isFileUploaded = true; } }); alertText.gameObject.SetActive(true); }
public async Task <string> UploadAnImageToFireBase(string fileURL, string fileNameWithOutExtension = "", string folderStructureName = "") { string response = ""; try { Stream streamResponse = new MemoryStream(); FileStream fs = new FileStream(fileURL, FileMode.Open, FileAccess.Read); using (System.IO.Stream stream = new FileStream(fileURL, FileMode.Open, FileAccess.Read)) { streamResponse = stream; var firebaseStorageReference = FirebaseStorage.GetInstance(FirebaseAppInstance).Reference; StorageReference storageFilesReference; if (string.IsNullOrEmpty(fileNameWithOutExtension)) { string fileNameWithExtension = Path.GetFileName(fileURL); storageFilesReference = firebaseStorageReference.Child(folderStructureName + fileNameWithExtension);// ("TemporaryTestFiles/" + fileNameWithExtension); } else { string fileExtension = Path.GetExtension(fileURL); storageFilesReference = firebaseStorageReference.Child(folderStructureName + fileNameWithOutExtension + fileExtension);// ("TemporaryTestFiles/" + fileNameWithOutExtension + fileExtension); } AndroidConversionService androidConversionService = new AndroidConversionService(); var urlBytes = await androidConversionService.GetBytesFromStream(streamResponse); if (urlBytes != null) { UploadTask uploadTask = storageFilesReference.PutBytes(urlBytes); //uploadTask.AddOnCompleteListener() } } } catch (System.Exception ex) { var msg = ex.Message + "\n" + ex.StackTrace; System.Diagnostics.Debug.WriteLine(msg); } return(response); }
public override Android.Views.View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Xamarin.Essentials.Platform.Init(Activity, savedInstanceState); Android.Views.View view = inflater.Inflate(Resource.Layout.fragment_add_test, container, false); storage = FirebaseStorage.GetInstance(FirebaseApp.InitializeApp(Activity)); reference = storage.GetReferenceFromUrl("gs://educationalsoftware-ba7e4.appspot.com"); #region Initialize fragment components btnAddQuestion = view.FindViewById <Android.Widget.Button>(Resource.Id.btnAddQuestions); etTestName = view.FindViewById <EditText>(Resource.Id.editTextTestName); etTestNotation = view.FindViewById <EditText>(Resource.Id.editTextTestNotation); etNumberOfQuestions = view.FindViewById <EditText>(Resource.Id.editTextQuestionNumber); imgViewAddTest = view.FindViewById <ImageView>(Resource.Id.imgViewCreateTest); btnUpload = view.FindViewById <Android.Widget.Button>(Resource.Id.btnAddTestUploadPhoto); btnChoose = view.FindViewById <Android.Widget.Button>(Resource.Id.btnAddTestChoosePhoto); #endregion btnChoose.Click += OnChooseClicked; btnUpload.Click += OnUploadClicked; btnAddQuestion.Click += OnAddQuestion; return(view); }
public void DownloadFile() { m_text.text = "Yükleniyor..."; storage = FirebaseStorage.GetInstance("gs://ar-demo-309912.appspot.com"); reference = storage.GetReferenceFromUrl(src); string Path = Application.persistentDataPath; if (File.Exists(Path + "/" + local)) { File.Delete(Path + "/" + local); } reference.GetFileAsync(Path + "/" + local).ContinueWithOnMainThread(task => { if (!task.IsFaulted && !task.IsCanceled) { m_text.text = ""; s_download = true; } if (task.IsFaulted) { m_text.text = "Dosyaya ulaşılamadı, böyle bir dosya olmayabilir"; } }); }
/// <summary> /// Set up the Downloader /// </summary> /// <param name="targetURL">current Storage URL</param> public Downloader(string targetURL) { Storage = FirebaseStorage.GetInstance(targetURL); }
private async void Init(string storage) { if (_inited || _initing) { return; } _initing = true; var status = await FirebaseDependencies.CheckAndFixDependencies(); switch (status) { case DependencyStatus.Available: { _storage = storage.IsNullOrEmpty()? FirebaseStorage.DefaultInstance : FirebaseStorage.GetInstance(storage); _initing = false; _inited = true; break; } default: { _initing = false; _inited = false; break; } } }
/// <summary> /// set Server storage url /// </summary> /// <param name="url">storage url</param> public void SetStorage(string url) { Storage = FirebaseStorage.GetInstance(url); Storage_ref = Storage.GetReferenceFromUrl(url); }