Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

[FirebaseStorage] FullMetaData.timeCreated & FullMetadata.updated throws exceptions when accessing via UploadTask.onStateChanged #350

Closed
firatagdas opened this issue Oct 18, 2020 · 1 comment
Assignees

Comments

@firatagdas
Copy link
Contributor

I was working on FirebaseStorage Web support.

class UploadTaskSnapshotWeb extends TaskSnapshotPlatform {
  firebase.UploadTaskSnapshot _uploadTaskSnapshot;

  UploadTaskSnapshotWeb(this._uploadTaskSnapshot) :
    super(convertToPlatformTaskState(_uploadTaskSnapshot.state), <String, dynamic> {
      'bytesTransferred': _uploadTaskSnapshot.bytesTransferred,
      'metadata': _uploadTaskSnapshot.metadata != null ? FullMetaDataWeb(_uploadTaskSnapshot.metadata, skipDateTime: true) : null,
      'totalBytes': _uploadTaskSnapshot.totalBytes
    });

  @override
  ReferencePlatform get ref {
    var ref = _uploadTaskSnapshot.ref;
    return ReferenceWeb(FirebaseStorageWeb(app: Firebase.app()), ref.fullPath, ref);
  }
}

class FullMetaDataWeb extends FullMetadata {
  FullMetaDataWeb(firebase.FullMetadata fullMetadata)
    : assert(fullMetadata != null), super(<String, dynamic> {
        'bucket': fullMetadata.bucket,
        'cacheControl': fullMetadata.cacheControl,
        'contentDisposition': fullMetadata.contentDisposition,
        'contentEncoding': fullMetadata.contentEncoding,
        'contentLanguage': fullMetadata.contentLanguage,
        'contentType': fullMetadata.contentType,
        'customMetadata': fullMetadata.customMetadata,
        'fullPath': fullMetadata.fullPath,
        'generation': fullMetadata.generation,
        'metadataGeneration': fullMetadata.metageneration,
        'md5Hash': fullMetadata.md5Hash,
        'name': fullMetadata.name,
        'size': fullMetadata.size,
        'creationTimeMillis': fullMetadata.timeCreated?.millisecond,
        'updatedTimeMillis': fullMetadata.updated?.millisecond
      }
    );
}

This code throws an exception because, accessing FullMetaData.timeCreated directly calls DateTime.parse without null safety. https://github.com/FirebaseExtended/firebase-dart/blob/master/firebase/lib/src/storage.dart#L217

I know there is no reason to access timeCreated during State Changes until it completes... But for the plugin sakes, it is necessary.

@kevmoo
Copy link
Contributor

kevmoo commented Oct 18, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants