无法将图像从 RPI 3 上传到 Firebase 存储

Can't upload image from RPI 3 to Firebase Storage

我正在尝试将图像从 Raspberry Pi 3 上传到 Firebase Storage 但无法上传。我尝试了不同版本的 __Firebase_ 库(11.4.2、11.6.0、11.8.0),但我总是得到相同的结果。 我使用 OS 构建 OIM1.171126.016

Firebase 来自 build.gradle 的依赖项:

compile "com.google.firebase:firebase-core:11.6.0"
compile "com.google.firebase:firebase-auth:11.6.0"
compile "com.google.firebase:firebase-messaging:11.6.0"
compile "com.google.firebase:firebase-firestore:11.6.0"
compile "com.google.firebase:firebase-storage:11.6.0"
compile "com.google.firebase:firebase-crash:11.6.0"

上传图片代码:

private void onPictureTaken(final byte[] imageBytes) {
        if (imageBytes != null) {
            Log.d(TAG, "Picture taken");
            StorageReference storageRef = storage.getReference();
            StorageReference feederRef = storageRef.child("test/test.jpg");

            feederRef.putBytes(imageBytes).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle unsuccessful uploads
                    Log.e(TAG, exception.getMessage(), exception);
                }
            }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    Uri downloadUrl = taskSnapshot.getDownloadUrl();
                    Log.d(TAG, "downaload uri = " + downloadUrl);
                }
            });
        }
    }

日志:

W/GooglePlayServicesUtil: Google Play services is missing.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.firebasestorage not found.
I/DynamiteModule: Considering local module com.google.android.gms.firebasestorage:0 and remote module com.google.android.gms.firebasestorage:0
E/NetworkRqFactoryProxy: NetworkRequestFactoryProxy failed with a RemoteException:
                         com.google.android.gms.dynamite.DynamiteModule$zzc: No acceptable module found. Local version is 0 and remote version is 0.
                             at com.google.android.gms.dynamite.DynamiteModule.zza(Unknown Source:176)
                             at com.google.android.gms.internal.zzewy.<init>(Unknown Source:18)
                             at com.google.android.gms.internal.zzewy.zzh(Unknown Source:13)
                             at com.google.firebase.storage.StorageReference.zzcjq(Unknown Source:8)
                             at com.google.firebase.storage.UploadTask.run(Unknown Source:105)
                             at com.google.firebase.storage.zzr.run(Unknown Source:2)
                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                             at java.lang.Thread.run(Thread.java:764)
E/UploadTask: Unable to create a network request from metadata
              android.os.RemoteException
                  at com.google.android.gms.internal.zzewy.<init>(Unknown Source:85)
                  at com.google.android.gms.internal.zzewy.zzh(Unknown Source:13)
                  at com.google.firebase.storage.StorageReference.zzcjq(Unknown Source:8)
                  at com.google.firebase.storage.UploadTask.run(Unknown Source:105)
                  at com.google.firebase.storage.zzr.run(Unknown Source:2)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                  at java.lang.Thread.run(Thread.java:764)
E/StorageException: StorageException has occurred.
                    An unknown error occurred, please check the HTTP result code and inner exception for server response.
                     Code: -13000 HttpResult: 0
E/StorageException: null
                    android.os.RemoteException
                        at com.google.android.gms.internal.zzewy.<init>(Unknown Source:85)
                        at com.google.android.gms.internal.zzewy.zzh(Unknown Source:13)
                        at com.google.firebase.storage.StorageReference.zzcjq(Unknown Source:8)
                        at com.google.firebase.storage.UploadTask.run(Unknown Source:105)
                        at com.google.firebase.storage.zzr.run(Unknown Source:2)
                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                        at java.lang.Thread.run(Thread.java:764)
E/StorageException: StorageException has occurred.
                    An unknown error occurred, please check the HTTP result code and inner exception for server response.
                     Code: -13000 HttpResult: 0
E/StorageException: null
                    android.os.RemoteException
                        at com.google.android.gms.internal.zzewy.<init>(Unknown Source:85)
                        at com.google.android.gms.internal.zzewy.zzh(Unknown Source:13)
                        at com.google.firebase.storage.StorageReference.zzcjq(Unknown Source:8)
                        at com.google.firebase.storage.UploadTask.run(Unknown Source:105)
                        at com.google.firebase.storage.zzr.run(Unknown Source:2)
                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                        at java.lang.Thread.run(Thread.java:764)
E/StorageException: StorageException has occurred.
                    An unknown error occurred, please check the HTTP result code and inner exception for server response.
                     Code: -13000 HttpResult: 0
E/StorageException: null
                    android.os.RemoteException
                        at com.google.android.gms.internal.zzewy.<init>(Unknown Source:85)
                        at com.google.android.gms.internal.zzewy.zzh(Unknown Source:13)
                        at com.google.firebase.storage.StorageReference.zzcjq(Unknown Source:8)
                        at com.google.firebase.storage.UploadTask.run(Unknown Source:105)
                        at com.google.firebase.storage.zzr.run(Unknown Source:2)
                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                        at java.lang.Thread.run(Thread.java:764)

Firebase 存储中的规则

service firebase.storage {
  match /b/my-app.appspot.com/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

我的代码有什么问题?

根据logcat消息:

W/GooglePlayServicesUtil: Google Play services is missing.

检查系统中是否安装了包 com.google.android.gms

adb shell pm list packages

如果包丢失,请尝试从控制台获取新的 Android Things 包并重新刷新映像。

您需要将 Google Play Services classPath 依赖项添加到您的根 build.gradle

buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:3.1.1' // google-services plugin
    }
}

allprojects {
    // ...
    repositories {
        // ...
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}

事物模块:

apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  // ...
  compile 'com.google.firebase:firebase-core:11.8.0'

  // Getting a "Could not find" error? Make sure you have
  // added the Google maven respository to your root build.gradle
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

更多信息here