亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

String downloadThumbUri = uploadTask.getResult()

String downloadThumbUri = uploadTask.getResult()

子衿沉夜 2023-07-28 15:11:29
如何獲取下載URI?String downloadThumbUri = uploadTask.getResult().getStorage().getDownloadUrl().toString();不管用。我正在使用位圖來壓縮圖像以將其用作縮略圖。這是代碼:ByteArrayOutputStream baos = new ByteArrayOutputStream();compressedImageFile.compress(Bitmap.CompressFormat.JPEG, 100, baos);byte[] thumbData = baos.toByteArray();final UploadTask uploadTask = storageReference.child("post_images/thumbs").child(randomName + ".jpg").putBytes(thumbData);uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {    @Override    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {        //Toast.makeText(NewPostActivity.this,"Thumbnail was uploaded ",Toast.LENGTH_LONG).show();        String downloadThumbUri = uploadTask.getResult().getStorage().getDownloadUrl().toString();        Map<String,Object> postMap = new HashMap<>();        postMap.put("image url",downloadUri);        postMap.put("thumb",downloadThumbUri);        postMap.put("desc",desc);        postMap.put("user_id",current_user_id);        postMap.put("timestamp",FieldValue.serverTimestamp());        firebaseFirestore.collection("Posts").add(postMap).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {            @Override            public void onComplete(@NonNull Task<DocumentReference> task) {                if(task.isSuccessful()){                    newPostProgress.setVisibility(View.INVISIBLE);                    Toast.makeText(NewPostActivity.this,"Post was added ",Toast.LENGTH_LONG).show();                    Intent mainIntent = new Intent(NewPostActivity.this,MainActivity.class);                    startActivity(mainIntent);                    finish();                }            }        })    }}
查看完整描述

1 回答

?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

使用以下代碼獲取下載 uri 并存儲在 Firestore 中。把它放在onSucess里面


uploadTask.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {

                @Override

                public void onComplete(@NonNull Task<Uri> task) {

                    String downloadThumbUri = task.getResult().toString();

                    Map<String,Object> postMap = new HashMap<>();

                    postMap.put("image url",downloadUri);

                    postMap.put("thumb",downloadThumbUri);

                    postMap.put("desc",desc);

                    postMap.put("user_id",current_user_id);

                    postMap.put("timestamp",FieldValue.serverTimestamp());


                    firebaseFirestore.collection("Posts").add(postMap).addOnCompleteListener(new OnCompleteListener<DocumentReference>() {

                        @Override

                        public void onComplete(@NonNull Task<DocumentReference> task) {


                            if(task.isSuccessful()){


                                newPostProgress.setVisibility(View.INVISIBLE);

                                Toast.makeText(NewPostActivity.this,"Post was added ",Toast.LENGTH_LONG).show();

                                Intent mainIntent = new Intent(NewPostActivity.this,MainActivity.class);

                                startActivity(mainIntent);

                                finish();

                            }

            });

        }

    })

    .addOnFailureListener(new OnFailureListener() {

        @Override

        public void onFailure(@NonNull Exception e) {

            progressBar.setVisibility(View.GONE);

            Toast.makeText(ProfileActivity.this, "aaa "+e.getMessage(), Toast.LENGTH_SHORT).show();

        }

    });


查看完整回答
反對 回復 2023-07-28
  • 1 回答
  • 0 關注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號