Hey I’m trying to upload all files located in a folder to firestore storage.
However im quite new to c# and unity.
I have the following code to upload a file located in the folder.
if(Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead)){
Debug.Log("Permissions Found");
var Directory_path = ("SparseSpatialMap/Copia.meta");
var path = (Application.persistentDataPath + "/" + Directory_path);
//Firestore Reference
storage = FirebaseStorage.DefaultInstance;
storageReference = storage.GetReferenceFromUrl("gs://houdini-ac884.appspot.com");
StreamReader stream = new StreamReader(path);
// Create a reference to the file you want to upload
StorageReference riversRef = storageReference.Child("uploads/newFile.meta");
// Upload the file to the path "uploads/newFile.meta"
riversRef.PutStreamAsync(stream.BaseStream)
.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.
StorageMetadata metadata = task.Result;
string md5Hash = metadata.Md5Hash;
Debug.Log("Finished uploading...");
Debug.Log("md5 hash = " + md5Hash);
}
});
} else {
Debug.Log("No Permissions");
Permission.RequestUserPermission(Permission.ExternalStorageRead);
return;
}
The file i uploaded with success is located here " /storage/emulated/0/Android/data/estg.easy.ar/files/SparseSpatialMap/Copia.meta "
I want to upload all files in the /SparseSpatialMap direcory
2
Answers
For anyone looking for the solution this was how i did it. got all files via their folder with DirectoryInfo and uploaded each individually using it's the respective name
What you’re looking for is a way to get all file names, or paths. Try importing System.IO if you have already then you can use
Directory.GetFiles(path)
replacing path with the folder directory. Then you should have an array of strings representing each file.