I'm trying to create a File object with the method File.fromUri(Uri.parse(uploadedImage)); where the input uploadedImage is an FFUploadedFile data type with data that comes from an image the user uploads. I'm trying to use the code below:
File file = File.fromUri(Uri.parse(uploadedImage));
final bytes = await file.readAsBytes();
final archiveFile = ArchiveFile('uploadedImages', bytes.length, bytes);
And uploaded image comes in the format: FFUploadedFile(name: 1700600326427000_0.png, bytes: 239701, height: null, width: null, blurHash: null,)
However, when I try to run the above Custom Code, I get the error message: "The argument type 'FFUploadedFile' can't be assigned to the parameter type 'String'"
How do I get File.fromUri to work with the FFUploadedFile data type as the input?
The error you're encountering indicates a type mismatch. The
File.fromUri
method expects aString
as input, which represents the URI of the file. However, you're passing anFFUploadedFile
object directly.To resolve this, you'll need to use the properties of the
FFUploadedFile
object to retrieve the necessary information, such as the bytes or the file path, and then create aFile
object.Look at bellow code segment,
This code assumes you have access to the
FFUploadedFile
properties such asbytes
andname
to retrieve the necessary information to create a temporary file usingFile
. Then, you can perform operations on this temporary file as required.