uploadWithBytes method

  1. @override
Future<RemoteFile> uploadWithBytes(
  1. Uint8List uploadFileByte,
  2. String remoteRelativePathOrId, {
  3. String? mimeType,
})
override

Uploads the data specified in uploadFileByte to remoteRelativePathOrId, which is the location on the remote side.

The byte data of the file is passed to uploadFileByte and the relative path is passed to remoteRelativePathOrId.

Return RemoteFile containing the full path of the upload destination and the actual data as the return value.

You can specify the MIME type for uploading with mimeType.

uploadFileByteで指定されたデータをリモート側の位置であるのremoteRelativePathOrIdにアップロードします。

uploadFileByteにファイルのバイトデータが渡されremoteRelativePathOrIdに相対パスが渡されます。

戻り値としてアップロード先のフルパスと実データを格納したRemoteFileを返してください。

mimeTypeでアップロード時のMIMEタイプを指定できます。

Implementation

@override
Future<RemoteFile> uploadWithBytes(
  Uint8List uploadFileByte,
  String remoteRelativePathOrId, {
  String? mimeType,
}) async {
  await FirebaseCore.initialize(options: options);
  try {
    assert(uploadFileByte.isNotEmpty, "Bytes is empty.");
    final metadata =
        mimeType != null ? SettableMetadata(contentType: mimeType) : null;
    final uploadTask =
        reference(remoteRelativePathOrId).putData(uploadFileByte, metadata);
    await Future.value(uploadTask);
    return RemoteFile(path: await fetchPublicURI(remoteRelativePathOrId));
  } catch (e) {
    rethrow;
  }
}