upload method
Uploads the local file specified in localFullPath to remoteRelativePathOrId, 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 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.
localFullPathで指定されたローカル上のファイルをリモート側の位置であるのremoteRelativePathOrIdにアップロードします。
localFullPathにプラットフォーム内のフルパスが渡されremoteRelativePathOrIdに相対パスが渡されます。
戻り値としてアップロード先のフルパスと実データを格納したRemoteFileを返してください。
mimeTypeでアップロード時のMIMEタイプを指定できます。
Implementation
@override
Future<RemoteFile> upload(
String localFullPath,
String remoteRelativePathOrId, {
String? mimeType,
}) 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 metadata =
mimeType != null ? SettableMetadata(contentType: mimeType) : null;
final uploadTask =
reference(remoteRelativePathOrId).putData(byte, metadata);
await Future.value(uploadTask);
return RemoteFile(path: await fetchPublicURI(remoteRelativePathOrId));
} catch (e) {
rethrow;
}
}