Skip to content

how can i load files as PlatformFile Type from file path and display them for edit purpose? #67

Answered by saifonglee
saifonglee asked this question in Q&A
Discussion options

You must be logged in to vote

problem solved... thanks!
solution
as my file path is an URL, i created this function based on this answer from Stackoverflow: https://stackoverflow.com/a/59589480

getFile(String? filePath) async {
final http.Response responseData = await http.get(Uri.parse(filePath!));
var name = filePath.split('/')[filePath.split('/').length - 1];
Uint8List uint8list = responseData.bodyBytes;
var buffer = uint8list.buffer;
ByteData byteData = ByteData.view(buffer);
var tempDir = await Directory.systemTemp.createTemp();
File file = await File('${tempDir.path}/$name').writeAsBytes(
buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
return file;
}

the second function is used to return f…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by saifonglee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant