2017-03-20 24 views
1

Ich brauche ein Foto zu meiner Feuerbasis Speicherung von lokalem Pfad zu laden, aber ich halte auf einen Fehler bekommenein lokales Bild hochladen zu Firebase Speichern (Unity3D)

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) 

Dies ist mein Code:

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); 
     } 

ich versuchte PutBytesAsync statt putFileAsync verwenden und nicht einen Fehler, aber die Art der hochgeladenen Datei ist application/octet-stream

ich Hilfe dringend brauchen. Vielen Dank!

Antwort

0

Scheint, wie es gibt zwei Probleme hier:

  1. Der erste Fehler ist von Could not find file "C:\Users\jorren\AppData\LocalLow\DefaultCompany\JKL\636256043481512729.jpg". Haben Sie überprüft, dass diese Datei auf der Festplatte vorhanden ist? Scheint so, als ob es nicht gefunden werden kann :(
  2. Der Inhaltstyp wird durch die Metadaten der Datei festgelegt und standardmäßig application/octet-stream, wenn wir ihn nicht finden können. Bei Dateien auf der Festplatte können wir oft den Inhaltstyp aus der Datei auswählen in Speicherdaten, aber für uns nicht einfach den Inhaltstyp in Ihren Metadaten festlegen (pro the docs)

Beispiel:..

// Create file metadata including the content type 
var new_metadata = new Firebase.Storage.MetadataChange(); 
new_metadata.ContentType = "image/jpeg"; 

// Upload data and metadata 
mountains_ref.PutBytesAsync(custom_bytes, new_metadata, ...)