writeLargeFile function
Send a large local file with path localFilePath to a remote server
using name remoteFilePath (relative to appname/data directory),
encrypt the file content if encrypted is true.
By default the file is written to the current user's own POD. To write to
the POD of another owner (e.g. a note or community POD shared with the
user), provide that owner's WebID via ownerWebId. This mirrors the
ownerWebId parameter of readLargeFile and the fileOwnerWebId
parameter of writeExternalPod. When writing to an external POD with
encryption, inheritKeyFrom must point to a directory whose encryption
key is shared with the user (the same contract as writeExternalPod),
otherwise the per-file encryption key would be stored unencrypted.
Set isPodRelativePath to true when remoteFilePath is relative to the
POD root (e.g. demopod/data/file.pdf) rather than the current app's data
directory. This is required to write a large file to a POD whose
application directory differs from the current app (for instance when the
destination URL supplied by the user names a different app).
Implementation
Future<void> writeLargeFile({
required String localFilePath,
required String remoteFilePath,
String? ownerWebId,
String? inheritKeyFrom,
bool createAcl = true,
bool isPodRelativePath = false,
void Function(int, int)? onProgress,
bool encrypted = true,
}) async {
final file = File(localFilePath);
final totalBytes = file.lengthSync();
await send(
dataStream: file.openRead(),
remoteFilePath: remoteFilePath,
totalBytes: totalBytes,
ownerWebId: ownerWebId,
inheritKeyFrom: inheritKeyFrom,
createAcl: createAcl,
isPodRelativePath: isPodRelativePath,
onProgress: (sent, total) {
if (onProgress != null) {
onProgress(sent, total!);
}
},
encrypted: encrypted,
);
}