【发布时间】:2018-12-21 02:09:54
【问题描述】:
我正在尝试将我从手机拍摄的图像发送到 Firebase 存储。第一个函数使用图像选择器插件获取图像并将路径返回作为上传函数的参数传递。图像上传到云存储,但在面板中类型为application/octet-stream,图像不显示
String download_path;
var imageFile;
picker() async{
File theImage = await ImagePicker.pickImage(
source: ImageSource.gallery);
imageFile = theImage;
var theimagepath = theImage.path;
setState(() {
imageFile = theImage;
});
}
Future<Null> uploadFile(String myfilepath)async{
final RegExp regExp = RegExp('([^?/]*\.(jpg))');
final filename = regExp.stringMatch(myfilepath);
final Directory tempDir = Directory.systemTemp;
final File thefile = await File('${tempDir.path}/$filename').create();
final StorageReference sref = FirebaseStorage.instance.ref().child('storeFolderName').child(filename);
final StorageUploadTask uploadTask = sref.putFile(thefile);
final Uri downloadUrl = (await uploadTask.future).downloadUrl;
download_path = downloadUrl.toString();
print('download url printed : $download_path');
}
IconButton(
icon: Icon(Icons.cloud_done),
onPressed: (){uploadFile(imageFile.toString());
},
),
日志输出:
D/Surface (18601): Surface::setBufferCount(this=0x9272d800,bufferCount=4)
D/GraphicBuffer(18601): register, handle(0x97ee29c0) (w:480 h:854 s:480 f:0x1 u:f02)
D/GraphicBuffer(18601): register, handle(0x97ee2e40) (w:480 h:854 s:480 f:0x1 u:f02)
D/GraphicBuffer(18601): register, handle(0x8ea20140) (w:480 h:854 s:480 f:0x1 u:f02)
W/System (18601): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(18601): e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp
I/System.out(18601): [OkHttp] sendRequest<<
D/GraphicBuffer(18601): register, handle(0x8ea21040) (w:480 h:854 s:480 f:0x1 u:f02)
W/System (18601): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(18601): e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp
I/System.out(18601): [OkHttp] sendRequest<<
I/flutter (18601): download url printed : https://firebasestorage.googleapis.com/v0/b/cloud-fs-demo.appspot.com/o/storeFolderName%2FIMG_20180711_080138.jpg?alt=media&token=6fb05871-04df-458d-93bc-1951cd122770
E/[EGL-ERROR](18601): __egl_platform_cancel_buffers:644: surface->num_buffers(4)
【问题讨论】:
-
请发布与上传相关的任何日志/异常情况。
标签: firebase flutter firebase-storage