将图片文件从素材资源上传到Firebase

时间:2020-07-21 20:17:10

标签: firebase flutter dart

我需要为我的应用程序的用户提供一个从他们的画廊中选择图像文件的选项,如果他们不想这样做,则可以从应用程序中提供的一组选项中进行选择。 我尝试使用以下代码做到这一点

void meds() async{
WidgetsFlutterBinding.ensureInitialized();
void initState() {
  super.initState();
  titleController = TextEditingController(text: "Take medicine");//to initialise textfield
}
file=await getImageFileFromAssets('assets/images/medicine.jpg');
setState(() {
  file=file;
  imagefilepath=basename(file.path);
  uploadImageFile(file.readAsBytesSync(),imagefilepath);
});}
Future<File> getImageFileFromAssets(String path) async {
WidgetsFlutterBinding.ensureInitialized();
final byteData = await rootBundle.load(path);

final file = File('${(await getTemporaryDirectory()).path}/$path');
await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));

return file;}

以上是用于从我的素材资源文件夹上传图片的代码段 我已经将该图片包含在资产中,并相应地在pubspec.yaml文件中进行了更改。

this is the error message when i try executing the upload

0 个答案:

没有答案
相关问题