【发布时间】:2017-03-20 03:23:58
【问题描述】:
我需要将我的照片从本地路径上传到我的 firebase 存储,但我不断收到错误
System.AggregateException: Exception of type 'System.AggregateException' was thrown.
Firebase.Storage.StorageException: An unknown error occurred, please check the HTTP result code and inner exception for server response. ---> System.IO.FileNotFoundException: Could not find file "C:\Users\jorren\AppData\LocalLow\DefaultCompany\JKL\636256043481512729.jpg".
File name: 'C:\Users\jorren\AppData\LocalLow\DefaultCompany\JKL\636256043481512729.jpg'
at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00209] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:305
at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
at System.IO.File.OpenRead (System.String path) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/File.cs:363
at Firebase.Storage.UploadTask..ctor (Firebase.Storage.StorageReference targetRef, Firebase.Storage.StorageMetadata metadata, System.String file, System.Uri existingUploadUri, System.Threading.Tasks.TaskCompletionSource`1 userTask, IProgress`1 progress, CancellationToken token, System.Threading.SynchronizationContext ctx) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
UnityEngine.Debug:Log(Object)
Kudan.AR.Samples.<uploadToStorage>c__Iterator1:MoveNext() (at Assets/KudanAR/Samples/Scripts/SampleApp.cs:122)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
这是我的代码:
Firebase.Storage.FirebaseStorage storage = Firebase.Storage.FirebaseStorage.DefaultInstance;
Firebase.Storage.StorageMetadata metadata;
// Create a storage reference from our storage service
Firebase.Storage.StorageReference storage_ref = storage.GetReferenceFromUrl("gs://sylpauljoyce-d9115.appspot.com");
Firebase.Storage.StorageReference rivers_ref = storage_ref.Child("images/" + filename);
string fileContents = Application.persistentDataPath + "/" + filename;
var task = rivers_ref.PutFileAsync(fileContents);
yield return new WaitUntil(() => task.IsCompleted);
if (task.IsFaulted) {
Debug.Log(task.Exception.ToString());
} else {
fileContents = "";
Debug.Log("Finished uploading... Download Url: " + task.Result.DownloadUrl.ToString());
url = task.Result.DownloadUrl.ToString ();
Debug.Log (url);
}
我尝试使用 PutBytesAsync 代替 putFileAsync 并没有收到错误,但上传的文件类型是 application/octet-stream
我非常需要帮助。谢谢!
【问题讨论】:
标签: android unity3d firebase firebase-storage