Flutter 웹 : firebase_storage : MissingPluginException StorageReference # putData 메소드에 대한 구현을 찾을 수 없습니다.

Aug 27 2020

UInt8List 형식의 이미지를 firebase 저장소에 업로드하려고합니다. "StorageReference.putData"를 사용하고 있습니다. putFile이 정의되지 않았다는이 오류가 계속 발생합니다. 모든 lated firebase 패키지로 업데이트했지만 여전히 성공하지 못했습니다. Flutter Web에서 putData가 불가능합니까?

나는 모든 패키지를 업데이트 한 다음 'flutter clean', 'flutter packages get'을 시도했습니다.

"putFile"을 사용하지 않는 이유는 Flutter Web이 putFile 사용에 필요한 특정 File 클래스를 보유하는 dart : io를 지원하지 않기 때문입니다.

오류:

Error: MissingPluginException(No implementation found for method StorageReference#putData on channel plugins.flutter.io/firebase_storage)
    at Object.throw_ [as throw] (http://localhost:60357/dart_sdk.js:4331:11)
    at MethodChannel._invokeMethod (http://localhost:60357/packages/flutter/src/services/system_channels.dart.lib.js:942:21)
    at _invokeMethod.next (<anonymous>)
    at http://localhost:60357/dart_sdk.js:37593:33
    at _RootZone.runUnary (http://localhost:60357/dart_sdk.js:37447:58)
    at _FutureListener.thenAwait.handleValue (http://localhost:60357/dart_sdk.js:32424:29)
    at handleValueCallback (http://localhost:60357/dart_sdk.js:32971:49)
    at Function._propagateToListeners (http://localhost:60357/dart_sdk.js:33009:17)
    at _Future.new.[_completeWithValue] (http://localhost:60357/dart_sdk.js:32852:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:60357/dart_sdk.js:32874:35)
    at Object._microtaskLoop (http://localhost:60357/dart_sdk.js:37708:13)
    at _startMicrotaskLoop (http://localhost:60357/dart_sdk.js:37714:13)
    at http://localhost:60357/dart_sdk.js:33226:9

내 업로드 기능 :

  Future<StorageTaskSnapshot> uploadImage(Uint8List imageFile, int pos) {
    return storageRef
        .child("posts/${currentUser.uid}/$_postId/$pos.jpg")
        .putData(imageFile)
        .onComplete;
  }

답변

1 broken.eggshell Sep 04 2020 at 07:13

나는 다른 사람들의 답변을 혼합 한 후에 마침내 이것을 작동시켰다. image_picker_for_web의 이미지로 시작합니다.

final picker = ImagePicker();
final new_image = await picker.getImage(
    source: source=='gallery' ? ImageSource.gallery : ImageSource.camera,
);

그때:

String url;
var bytes = await new_image.readAsBytes();
try {
    fb.StorageReference _storage = fb.storage().ref('002test');
    fb.UploadTaskSnapshot uploadTaskSnapshot = await _storage.put(bytes, fb.UploadMetadata(contentType: 'image/png')).future;
    var imageUri = await uploadTaskSnapshot.ref.getDownloadURL();
    url = imageUri.toString();
} catch (e) {
    print(e);
}

이것이 저를 올바른 방향으로 안내 한 SO였습니다. Flutter Web Upload to Firestore