我正在写一个应用程序,它可以从图库中选择一张图片并上传到firestore的文件夹中。
await Future.forEach(_paths.entries, (v) async {
String uid = Uuid().v1();
StorageReference imgReference =
_storageReference.child("Form2").child(uid);
StorageUploadTask task = imgReference.putFile(
File(v.value)
);
StorageTaskSnapshot downloadURL = await
task.onComplete;
String value = await downloadURL.ref.getDownloadURL();
paths[uid] = value;
}图像未上载到文件夹中。但它是直接上传到firestore中的
发布于 2019-08-10 02:29:15
您必须在.child()中指定文件夹名称。比如:.child("/$folder").child("$fileName")。
示例:
StorageReference ref = FirebaseStorage.instance.ref().child('/$folder').child(fileName);
StorageUploadTask uploadTask = ref.putData(imageData);
print('Upload triggered in the background.');
...
return await (await uploadTask.onComplete).ref.getDownloadURL();}
发布于 2019-08-10 03:36:37
这是一段将带有名称的图像上传到firebase的代码。Sliderutils是一个具有getName()和getImageUrl()函数(getters和setters)的类。
StorageReference Ref=
mStorageRef.child(System.currentTimeMillis()+"."+getPath(filePath));
mStorageTask = Ref.putFile(filePath)
.addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(MainActivity.this, "Image uploaded successfully.", Toast.LENGTH_LONG).show();
SliderUtils sliderUtils = new SliderUtils(EditTextName.getText().toString().trim(),
taskSnapshot.getDownloadUrl().toString());
String uploadId = mDatabaseRef.push().getKey();
mDatabaseRef.child(uploadId).setValue(sliderUtils);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Toast.makeText(MainActivity.this,"Image upload failed.",Toast.LENGTH_SHORT).show();
}
})https://stackoverflow.com/questions/57435335
复制相似问题