我想上传一些文件和图片到firebase存储和实时数据库,但数据将被归类为in this format在实时和存储。
我可以在存储中成功地实现这一点,但我不能实时做到这一点。
这是我的代码上传数据到firebase存储和实时数据库
private void uploadFilesToStorage(String userKey, List<Uri> list, String listName) {
StorageReference mReference = sReference.child(mycertificate.getCert_num()
+ "/");
urls = new ArrayList<>();
wholeList = new LinkedHashMap<>();
for (Uri uri : list) {
StorageReference sr = mReference.child(listName + "/"
+ System.currentTimeMillis() + "."
+ Tools.getFileExtn(BrowseFiles.this,
uri));
sr.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
sr.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
urls.add(uri.toString());
wholeList.put(listName,urls);
Model model = new Model(userKey, mycertificate.getCert_num(),
mycertificate.getCert_date(), mycertificate.getComp_name(),
mycertificate.getComp_num(), mycertificate.getCountry(),
mycertificate.getTrans(), mycertificate.isModel_13(),
mycertificate.isChk_fact(), mycertificate.getOffers()
, wholeList);
uploadDataToRTDB(model);
}
});
}
});
}
}
private void uploadDataToRTDB(Model model) {
DatabaseReference reference = FirebaseDatabase.getInstance()
.getReference("Database");
reference.child("myfiles")
.child(modal.getCert_num).setValue(model);
}
字符串
我把它叫做主活动
for (int i = 0; i < mylists.size(); i++) {
uploadFilesToStorage(UUID, mylists.get(i),
fragmentsIndx.get((i + 1)));
}
型
mylists是一个List<List< Uri>>,里面有我想上传的所有列表。
当我运行我的应用程序时,我在实时数据库中得到this result:
的数据
- 所有URL已添加到所有类别。*
我该怎么解决这个问题呢?
- 编辑 * 这是我的build.gradle文件
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.gms.google-services")
}
android {
namespace = "com.mkandeel.kodsadmin"
compileSdk = 33
buildFeatures {
viewBinding = true
}
defaultConfig {
applicationId = "com.mkandeel.kodsadmin"
minSdk = 23
targetSdk = 33
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.9.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.firebase:firebase-messaging-ktx:23.2.1")
implementation("com.google.firebase:firebase-messaging:23.2.1")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
implementation("com.google.firebase:firebase-auth-ktx:22.1.2")
implementation("com.google.firebase:firebase-database:20.2.2")
implementation("com.google.firebase:firebase-auth:22.1.2")
implementation("com.google.firebase:firebase-database-ktx:20.2.2")
implementation("com.google.firebase:firebase-storage-ktx:20.2.1")
implementation("com.google.firebase:firebase-storage:20.2.1")
implementation(platform("com.google.firebase:firebase-bom:32.3.1"))
implementation("com.google.firebase:firebase-analytics-ktx")
implementation ("androidx.preference:preference:1.2.1")
// retrofit
implementation ("com.squareup.retrofit2:retrofit:2.9.0")
// GSON
implementation ("com.squareup.retrofit2:converter-gson:2.9.0")
implementation ("com.google.code.gson:gson:2.9.0")
// okhttp3
implementation ("com.squareup.okhttp3:logging-interceptor:4.9.3")
}
型
这是我的模型课
package com.mkandeel.kodsadmin.models;
import java.util.List;
import java.util.Map;
public class Model {
private String cert_num;
private String cert_date;
private String comp_name;
private String comp_num;
private String country;
private String trans;
private boolean model_13;
private boolean isFact;
private String offers;
private List<List<String>> lists;
private String userKey;
public Model(){}
public Model(String userKey,String cert_num, String cert_date, String comp_name, String comp_num, String country, String trans, boolean model_13, boolean isFact, String offers, List<List<String>> lists) {
this.cert_num = cert_num;
this.cert_date = cert_date;
this.comp_name = comp_name;
this.comp_num = comp_num;
this.country = country;
this.trans = trans;
this.model_13 = model_13;
this.isFact = isFact;
this.offers = offers;
this.lists = lists;
this.userKey = userKey;
}
public List<List<String>> getLists() {
return lists;
}
public void setLists(List<List<String>> lists) {
this.lists = lists;
}
public String getUserKey() {
return userKey;
}
public void setUserKey(String userKey) {
this.userKey = userKey;
}
public String getCert_num() {
return cert_num;
}
public void setCert_num(String cert_num) {
this.cert_num = cert_num;
}
public String getCert_date() {
return cert_date;
}
public void setCert_date(String cert_date) {
this.cert_date = cert_date;
}
public String getComp_name() {
return comp_name;
}
public void setComp_name(String comp_name) {
this.comp_name = comp_name;
}
public String getComp_num() {
return comp_num;
}
public void setComp_num(String comp_num) {
this.comp_num = comp_num;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getTrans() {
return trans;
}
public void setTrans(String trans) {
this.trans = trans;
}
public boolean isModel_13() {
return model_13;
}
public void setModel_13(boolean model_13) {
this.model_13 = model_13;
}
public boolean isFact() {
return isFact;
}
public void setFact(boolean fact) {
isFact = fact;
}
public String getOffers() {
return offers;
}
public void setOffers(String offers) {
this.offers = offers;
}
}
型
1条答案
按热度按时间zbdgwd5y1#
试试下面的代码:
字符串