public void UploadFile() { // Get a reference to the storage service, using the default Firebase App FirebaseStorage storage = FirebaseStorage.DefaultInstance; // FirebaseStorage storage = FirebaseStorage.GetInstance("gs://basicfileupload.appspot.com") ; // Create a storage reference from our storage service StorageReference storage_ref = storage.GetReferenceFromUrl("gs://basicfileupload.appspot.com"); // Create a child reference // images_ref now points to "images" StorageReference testFileRef = storage_ref.Child($"Testing/{fileName.text}"); string download_url; // Upload the file to the path "images/rivers.jpg" testFileRef.PutFileAsync(fileName.text) .ContinueWith((Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); } else { Task <Uri> dloadTask = testFileRef.GetDownloadUrlAsync(); download_url = dloadTask.Result.ToString(); Debug.Log("Finished uploading..."); Debug.Log("download url = " + download_url); } }); }
private void SetCloudItinerary() { if (itinerary.Contains(SystemInfo.deviceUniqueIdentifier) == false) { //write to file string path = Directory.GetCurrentDirectory() + "\\" + folderName + "\\" + "Itinerary.txt"; ValidateDirectory(); ValidateFile("Itinerary.txt"); itinerary.Add(SystemInfo.deviceUniqueIdentifier); File.WriteAllText(path, JsonConvert.SerializeObject(itinerary, Formatting.Indented)); //upload to cloud FirebaseStorage storage = FirebaseStorage.DefaultInstance; StorageReference storage_ref = storage.GetReferenceFromUrl(networkURL); StorageReference fileRef = storage_ref.Child($"TanabataData/Itinerary.txt"); fileRef.PutFileAsync(path).ContinueWith((Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); } else { Debug.Log("Itinerary finished uploading..."); } }); } }
/* The function call to be allowed only if network is available * Get yipli pc app url from backend */ public static async Task <string> UploadLogsFileToDB(string userID, List <string> fileNames, List <string> filePaths) { StorageReference storageRef = yipliStorage.RootReference; string storageChildRef = "customer-tickets/" + userID + "/" + DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + "/" + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + "/"; for (int i = 0; i < fileNames.Count; i++) { StorageReference fmResponseLogRef = storageRef.Child(storageChildRef + fileNames[i]); await fmResponseLogRef.PutFileAsync(filePaths[i]).ContinueWith((Task <StorageMetadata> 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. StorageMetadata metadata = task.Result; string md5Hash = metadata.Md5Hash; Debug.Log("Finished uploading..."); Debug.Log("md5 hash = " + md5Hash); } }); } return(storageChildRef); }
private void StoreCSVToFirebase(string path) { // Create a root reference StorageReference storage_ref = storage.RootReference; // Create a reference to the file you want to upload string childString = path.Substring(path.IndexOf("/Analytics/")); StorageReference csv_ref = storage_ref.Child(childString); // Upload the file to the path csv_ref.PutFileAsync(path); }
public void UploadMap() { reference.PutFileAsync(FirebaseWorldMapPath).ContinueWith((Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log("Failed to upload map."); Debug.Log(task.Exception.InnerException.Message); } else { Debug.Log("Successfully uploaded map."); } }); }
// Upload a file from the local filesystem to Cloud Storage. protected IEnumerator UploadFromFile(string localFilename) { string localFilenameUriString = PathToPersistentDataPathUriString(localFilename); StorageReference storageReference = GetStorageReference(); DebugLog(String.Format("Uploading '{0}' to '{1}'...", localFilenameUriString, storageReference.Path)); var task = storageReference.PutFileAsync( localFilenameUriString, StringToMetadataChange(fileMetadataChangeString), new StorageProgress <UploadState>(DisplayUploadState), cancellationTokenSource.Token, null); yield return(new WaitUntil(() => task.IsCompleted)); //yield return new WaitForTaskCompletion(this, task); DisplayUploadComplete(task); }
public static void UploadFile(string localURL, string saveName, string saveAt) { StorageReference fileRef = storage.RootReference.Child(saveAt + "/" + saveName); fileRef.PutFileAsync(localURL).ContinueWith((Task <StorageMetadata> 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 md5hash. StorageMetadata metadata = task.Result; string md5Hash = metadata.Md5Hash; Debug.Log("Finished uploading..."); Debug.Log("md5 hash = " + md5Hash); } }); }
public static void SaveItemImage(Item item) { // Create a reference for the image StorageReference imageReference = FirebaseStorage.DefaultInstance.GetReference("images").Child("items").Child(item.itemId); // Upload the image to the path (images/items/(item.itemName)) imageReference.PutFileAsync(item.itemImagePath.ToString()).ContinueWith((Task <StorageMetadata> task) => { if (task.IsCanceled || task.IsFaulted) { // Error happened Debug.Log(task.Exception.ToString()); ViewMessageOnScreen(task.Exception.ToString()); } else { // Metadata contains file metadata such as file size, content type and downloadURL StorageMetadata metadata = task.Result; Debug.Log("Finished Uploading .... "); // Gets the download url imageReference.GetDownloadUrlAsync().ContinueWith((url) => { if (url.IsCompleted) { Debug.Log("Image download url: " + url.Result.AbsoluteUri.ToString()); FirebaseDatabase.DefaultInstance.GetReference("items").Child(item.itemId).Child("itemImageDownloadUrl").SetValueAsync(url.Result.AbsoluteUri.ToString()); //FirebaseDatabase.DefaultInstance.GetReference("users").Child(Globals.userId).Child("cart").Child(item.itemName).Child("itemImageDownloadUrl").SetValueAsync(url.Result.AbsoluteUri.ToString()); item.itemImageDownloadUrl = url.Result.AbsoluteUri.ToString(); snapshotsLoaded = true; ViewMessageOnScreen("Uploaded Image ... "); //AddItemToUserCart(item, Globals.userId.ToString()); } else { Debug.Log("Image not uploaded ... "); ViewMessageOnScreen("Image not uploaded check internet connection ... "); } }); } }); }
public static void UserUploadToFirebase(LevelManager.Level level) { DatabaseReference data = FirebaseDatabase.DefaultInstance.GetReferenceFromUrl("https://blockquest-a1e16.firebaseio.com/"); StorageReference levelFolder = root.Child(saveLoc); StorageReference userName = levelFolder.Child(FormattedUserName); StorageReference userLevel = userName.Child(level.LevelName); StorageReference levelFile = userLevel.Child(level.LevelName + ".xml"); StorageReference levelPic = userLevel.Child(level.LevelName + ".png"); levelFile.PutFileAsync(level.LevelPath); levelPic.PutBytesAsync(level.LevelPic.EncodeToPNG()); Level newLevel = new Level(level.LevelName, levelFile.Path, levelPic.Path); Debug.Log(levelFile.Path); Debug.Log(levelPic.Path); data.Child(saveLoc).Child(FirebaseManager.FormattedUserName).Child(level.LevelName).Child("File_Path").SetValueAsync(newLevel.filePath); data.Child(saveLoc).Child(FirebaseManager.FormattedUserName).Child(level.LevelName).Child("Picture_Path").SetValueAsync(newLevel.picturePath); }
public static void UploadFileToFirebase(LevelManager.Level level) { DatabaseReference data = FirebaseDatabase.DefaultInstance.GetReferenceFromUrl("https://blockquest-a1e16.firebaseio.com/"); StorageReference levelFolder = root.Child(saveLoc); StorageReference userLevel = levelFolder.Child(level.LevelName); StorageReference levelFile = userLevel.Child(level.LevelName + ".xml"); StorageReference levelPic = userLevel.Child(level.LevelName + ".png"); levelFile.PutFileAsync(level.LevelPath); levelPic.PutBytesAsync(level.LevelPic.EncodeToPNG()); Level newLevel = new Level(level.LevelName, levelFile.Path, levelPic.Path); data.Child(saveLoc).Child(level.LevelName).Child("File_Path").SetValueAsync(newLevel.filePath); data.Child(saveLoc).Child(level.LevelName).Child("Picture_Path").SetValueAsync(newLevel.picturePath); if (saveLoc == "Default_Levels") { data.Child("Base_Level_Last_Changed").SetValueAsync(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); } }
private void SetSaveToFirebase() { string path = Directory.GetCurrentDirectory() + "\\" + folderName + "\\" + fileName; FirebaseStorage storage = FirebaseStorage.DefaultInstance; StorageReference storage_ref = storage.GetReferenceFromUrl(networkURL); StorageReference fileRef = storage_ref.Child($"TanabataData/{SystemInfo.deviceUniqueIdentifier}/{fileName}"); fileRef.PutFileAsync(path).ContinueWith((Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); } else { Debug.Log("Finished uploading..."); } }); StartCloudItinerary(); }
public void UploadImagesToFirebase(List <string> Paths) { FilePath = Paths; //Creating a different session everytime the user wants create a scene Debug.Log("Module Started"); string sessionReference = CreateUserSession(); Firebase.Storage.StorageReference session_ref = user_ref.Child(sessionReference); MetadataChange type = new MetadataChange { ContentType = "image/jpeg" }; int Counter = 0; foreach (string ImagePath in Paths) { string imageName = "Image_" + Counter.ToString() + ".JPG"; Counter++; StorageReference folder_ref = session_ref.Child(imageName); folder_ref.PutFileAsync(ImagePath, type) .ContinueWith((Task <StorageMetadata> task) => { if (task.IsFaulted || task.IsCanceled) { Debug.Log(task.Exception.ToString()); } else { StorageMetadata metadata = task.Result; string download_url = metadata.DownloadUrl.ToString() + "\n"; UTF8Encoding uniEncoding = new UTF8Encoding(true); File.WriteAllText(fileName, download_url); images.Add(download_url); Debug.Log(download_url); uploadCount++; CheckIfComplete(); } } ); } }
private IEnumerator StoreImages(StorageReference storageReference, Item item, string name) { String path = item.id; string id = path.Substring(path.LastIndexOf("/", StringComparison.Ordinal), path.Length); StorageReference reference = storageReference.Child(PathString.Images).Child(name).Child(id); var storagetask = reference.PutFileAsync(path); yield return(new WaitUntil(() => storagetask.IsCompleted)); CodelabUtils._ShowAndroidToastMessage("Upload completed Successfully"); var uritask = storagetask.Result.Reference.GetDownloadUrlAsync(); yield return(new WaitUntil(() => uritask.IsCompleted)); String uri = uritask.Result.ToString(); imageURLs.Add(uri); CodelabUtils._ShowAndroidToastMessage($"Successfully stored Uri to list : {uri}"); //StartCoroutine(GetFileUri(storagetask.Result)); }