copyToTempWithResourceId method
Copies this file to the app's temporary directory using the given resourceId as the base filename.
- If the file is in HEIC format (
isHeic == true), it will be converted to JPEG usingHeifConverter.convert. - Otherwise, the file is copied as-is to the temp directory.
The new filename will be: [resourceId].jpeg for HEIC,
or [resourceId].[originalExtension] for other types.
This is typically used before uploading or previewing a normalized version of a file without modifying the original.
Returns the newly created File instance in the temp directory.
Example:
final normalized = await file.copyToTempWithResourceId('abc123');
print(normalized.path); // /tmp/abc123.jpeg
Implementation
Future<File> copyToTempWithResourceId(String resourceId) async {
final extension = isHeic ? '.jpeg' : p.extension(path);
final basename = '$resourceId$extension';
final targetPath = p.normalize(p.join(StorageEnvironment.instance.temporaryPath, basename));
if (isHeic) {
await HeifConverter.convert(path, output: targetPath, format: "jpeg");
} else {
await copy(targetPath);
}
return File(targetPath);
}