public void uploadFile(string filename, int size) { Debug.Log("upload file start."); byte[] data = new byte[size]; StorageReference storageReference = mAGCStorageManagement.getStorageReference(filename); UploadTask task = storageReference.putBytes(data, new FileMetadata()); task.addOnFailureListener(new MyFailureListener()) .addOnSuccessListener(new MySuccessListener()) .addOnProgressListener(new MyProgressListener()) .addOnPausedListener(new MyPausedListener()); StorageTask.ErrorResult err = new MyErrorResult(); Exception e = err.getError(); task.setResult(err.obj); err = task.getResult(); if (err == null) { Debug.Log("uploadFileTest fail, getResult err is null."); return; } StorageTask.ErrorResult timePointState = task.getTimePointState(); if (timePointState == null) { Debug.Log("uploadFileTest fail, getTimePointState result is null."); return; } Exception exp = task.getException(); if (exp == null) { Debug.Log("uploadFileTest fail, getException result is null."); return; } task.setException(exp); AndroidJavaObject ajObj = task.getResultThrowException(new AndroidJavaClass("java.lang.Exception")); if (ajObj == null) { Debug.Log("uploadFileTest fail, getException result is null."); return; } Debug.Log("upload file test success."); }
private void downloadTest() { Debug.Log("downloadTest start"); StorageReference reference = mAGCStorageManagement.getStorageReference(storageFileName); Debug.Log("getStorageReference end"); string downloadFilePath = downloadFileFolder + "downloadTest.cpp"; Debug.Log("downloadFilePath: " + downloadFilePath); File file = new File(downloadFilePath); try { DownloadTask task = reference.getFile(file); if (task == null) { Debug.Log("downloadTask is null"); } else { Debug.Log("downloadTask is not null"); StorageTask.ErrorResult err = new MyErrorResult(); Exception e = err.getError(); task.setResult(err.obj); err = task.getResult(); if (err == null) { Debug.Log("downloadFileTest fail, getResult err is null."); return; } StorageTask.ErrorResult timePointState = task.getTimePointState(); if (timePointState == null) { Debug.Log("downloadFileTest fail, getTimePointState result is null."); return; } Exception exp = task.getException(); if (exp == null) { Debug.Log("downloadFileTest fail, getException result is null."); return; } task.setException(exp); AndroidJavaObject ajObj = task.getResultThrowException(new AndroidJavaClass("java.lang.Exception")); if (ajObj == null) { Debug.Log("downloadFileTest fail, getException result is null."); return; } Debug.Log("downloadTest Success"); } } catch (System.Exception e) { Debug.Log(e); } }