[英]upload files to firebase storage not working
when I try to upload image to firebase storage using flutter, it doesn't work.当我尝试使用 flutter 将图像上传到 firebase 存储时,它不起作用。 It does not give error, but not load to the android divice.
它不会给出错误,但不会加载到 android 设备。 It just show running gradle task 'assemble task'.. it does not go from there
它只显示正在运行 gradle 任务“组装任务”.. 它不是从那里运行 go
here is my codes which i used to upload images noticeUpload.dart这是我用来上传图片的代码 noticeUpload.dart
import 'dart:io';
import 'dart:async';
import 'package:image_picker/image_picker.dart';
import 'package:flutter/material.dart';
import 'package:firebase_storage/firebase_storage.dart';
class NoticeUpload extends StatefulWidget {
@override
_NoticeUploadState createState() => _NoticeUploadState();
}
class _NoticeUploadState extends State<NoticeUpload> {
File sampleImage;
Future getImage()async{
var tempImage= await ImagePicker.pickImage(source: ImageSource.gallery );
setState(() {
sampleImage=tempImage;
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(
title: Text('Upload Notices'),
),
body: Row(
children:<Widget>[
sampleImage==null? Text('select image'):enableUpload(),
RaisedButton(
onPressed: getImage,
child: Text('uppload image'),
),
RaisedButton(
onPressed: (){
},
child:Text('uppload file') ,
)
]
),
);
}
Widget enableUpload(){
return Container(
child: Column(
children: <Widget>[
Image.file(sampleImage,height:200.0,width:100.0),
RaisedButton(
child:Text('Upload') ,
onPressed: (){
final StorageReference firebaseStorageRef=
FirebaseStorage.instance.ref().child('myimage.jpg');
final StorageUploadTask task=firebaseStorageRef.putFile(sampleImage);
},
)
],
),
);
}
}
this is the build.gradle file.这是 build.gradle 文件。
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
subprojects{
project.configurations.all{
resolutionStrategy.eachDependency{ details ->
if(details.requested.group=='com.android.support'
&& !details.requested.name.contains('multidex')
){
details.useVersion "28.0.0"
}
}
}
}
final ref = FirebaseStorage.instance
.ref()
.child('user_image')
.child(_authResult.user.uid + '.jpg');
await ref.putFile(file).onComplete;
final url = await ref.getDownloadURL();
print("Image URL: " + url);
Follow above code and check you are getting URL or not, if you configured firebase properly in your project then it should work;按照上面的代码检查你是否得到 URL,如果你在项目中正确配置了 firebase 那么它应该可以工作;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.