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.
localFullPath
で指定されたローカル上のファイルをリモート側の位置であるのremoteRelativePathOrId
にアップロードします。
localFullPath
にプラットフォーム内のフルパスが渡されremoteRelativePathOrId
に相対パスが渡されます。
戻り値としてアップロード先のフルパスと実データを格納したRemoteFile
を返してください。
Implementation
@override
Future<RemoteFile> upload(
String localFullPath,
String remoteRelativePathOrId,
) async {
if (!await localStorage.exists(localFullPath)) {
throw Exception("File could not be found: $localFullPath");
}
final bytes = await localStorage.read(localFullPath);
final remoteFullPath = await remoteStorage.fetchURI(remoteRelativePathOrId);
if (await remoteStorage.exists(remoteFullPath)) {
await remoteStorage.delete(remoteFullPath);
}
await remoteStorage.write(remoteFullPath, bytes);
return RemoteFile(
path: await fetchPublicURI(remoteRelativePathOrId),
bytes: bytes,
);
}