upload method

  1. @override
Future<RemoteFile> upload(
  1. String localFullPath,
  2. String remoteRelativePath
)
override

Uploads the local file specified in localFullPath to remoteRelativePath, which is the location on the remote side.

The full path in the platform is passed to localFullPath and the relative path is passed to remoteRelativePath.

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

localFullPathで指定されたローカル上のファイルをリモート側の位置であるのremoteRelativePathにアップロードします。

localFullPathにプラットフォーム内のフルパスが渡されremoteRelativePathに相対パスが渡されます。

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

Implementation

@override
Future<RemoteFile> upload(
  String localFullPath,
  String remoteRelativePath,
) async {
  await FirebaseCore.initialize(options: options);
  try {
    assert(localFullPath.isNotEmpty, "Path is empty.");
    if (localFullPath.startsWith("http")) {
      return RemoteFile(path: Uri.parse(localFullPath));
    }
    final byte = await Api.readBytes(localFullPath);
    final uploadTask = reference(remoteRelativePath).putData(byte);
    await Future.value(uploadTask);
    return RemoteFile(path: await fetchPublicURI(remoteRelativePath));
  } catch (e) {
    rethrow;
  }
}