gpt4 book ai didi

Android Tasksnapshot getDownloadUrl() 不同的 token

转载 作者:行者123 更新时间:2023-11-29 16:52:23 25 4
gpt4 key购买 nike

我在将图片上传到 Firebase 时遇到问题。

当我上传图像时,我得到一个 taskSnapshot.getDownloadUrl() token ,当我查看 firebase 存储时,有一个不同的 token key 。我无法弄清楚我的问题出在哪里,也不是每次我都收到错误(大约 30% 的时间)。

希望你能帮助我。

我的上传方式:

 public void uploadImage(Context context, Activity activity) {
String authorities = activity.getPackageName() + ".fileprovider";
File f = new File(MainActivity.imagesPath + String.valueOf(uploadToiletId) + "_" + uploadTimeStamp + ".png");
Log.i("HANDLERTAG", "file: " + f.getPath());
Uri imageUri = FileProvider.getUriForFile(context, authorities, f);
Log.i("HANDLERTAG", "image: " + imageUri.getPath());
Bitmap bitmap;
ByteArrayOutputStream baos;
final DatabaseReference databaseRef = FirebaseDatabase.getInstance().getReference();
final StorageReference storageRef = FirebaseStorage.getInstance().getReference();
final FirebaseAuth mAuth = FirebaseAuth.getInstance();
try {

bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), imageUri);
Bitmap resized = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() / 4, bitmap.getHeight()/ 4, true);
baos = new ByteArrayOutputStream();
resized.compress(Bitmap.CompressFormat.PNG, 50, baos);
byte[] dataBAOS = baos.toByteArray();
final String timeStamp = FormatHelper.getCurrentDateTimeString("dd-MM-yy HH:mm:ss");
StorageReference imagesRef = storageRef.child(String.valueOf(uploadToiletId)).child(timeStamp + ".png");
imagesRef.putBytes(dataBAOS).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.i("CAMERATAG", "Billede uploadet");
Uri downloadUrl = taskSnapshot.getDownloadUrl();
Log.i("DOWNLOAD_URL",String.valueOf(downloadUrl));
HashMap<String, String> UploadImageMap = new HashMap<>();
UploadImageMap.put("Url", downloadUrl.toString());
UploadImageMap.put("UserId", mAuth.getCurrentUser().getUid());
databaseRef.child(DB_TABLE_TOILETS)
.child(String.valueOf(uploadToiletId))
.child("Images")
.child(timeStamp).setValue(UploadImageMap);
databaseRef.child(DB_TABLE_USERS)
.child(mAuth.getCurrentUser().getUid())
.child("Images")
.child(String.valueOf(uploadToiletId))
.child(timeStamp).setValue(UploadImageMap);
}
});
imagesRef.putBytes(dataBAOS).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.i("CAMERATAG", e.getLocalizedMessage());
Log.i("CAMERATAG", "Noget gik galt med billede");
}
});
Toast.makeText(context, "Upload complete", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Log.i("HANDLERTAG", e.getMessage());
e.printStackTrace();
}
}

Debug shows token key from my app in android studio

token key :token=b23e8ab1-8322-46cf-889e-4f276fb2c242

Token from firebase

来自 firebase 的 token key :token=e5b84bed-7226-4af3-b01b-e31cf03e7d8b

最佳答案

您是否尝试过将存储设置为 read true?

service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read;
allow write: if request.auth != null;
}
}
}

这样用户无需登录即可阅读,但必须登录才能实际写入您的存储。

关于Android Tasksnapshot getDownloadUrl() 不同的 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45974932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com