当前位置: 首页 > 知识库问答 >
问题:

无法在FirebaseStorage上上载图像

狄凯
2023-03-14

我无法上载firebase存储上的配置文件图像。我正在把烤面包片上的错误打印出来。为什么会出现这种情况?我无法解决这个问题,我审查了我的代码很多次。问题可能是什么?我如何调整我的代码以使其正常工作?提前向大家表示感谢。

public class ProfiloUtenteActivity extends AppCompatActivity {

    private ImageView mImageBtn;
    private ImageView mSettingsBtn, mPersonalReviewsBtn, mShowFriendsBtn;
    private CircleImageView mProfileImage;
    private TextView mMailAcc, mUsernameAcc;

    private static final int GALLERY_PICK = 1;

    private DatabaseReference mUserDatabase;
    private FirebaseUser mCurrentUser;
    private ProgressDialog mProgress;

    private StorageReference mImageStorage;
    private String myUri = "";
    private Uri imageUri;

    FirebaseAuth auth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profilo_utente);

        mShowFriendsBtn = findViewById(R.id.imageShowFriends);
        mPersonalReviewsBtn = findViewById(R.id.imagePersonalReviews);
        mSettingsBtn = (ImageView) findViewById(R.id.imageViewSettings);
        mImageBtn = (ImageView) findViewById(R.id.change_image_btn);
        mProfileImage = (CircleImageView) findViewById(R.id.profile_image);
        mMailAcc = (TextView) findViewById(R.id.textViewMailAcc);
        mUsernameAcc = (TextView) findViewById(R.id.textView7);

        auth = FirebaseAuth.getInstance();

        mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
        String current_uid = mCurrentUser.getUid();

        mUserDatabase = FirebaseDatabase.getInstance().getReference().child("utenti").child(current_uid);
        mImageStorage = FirebaseStorage.getInstance().getReference();

mImageBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent galleryIntent = new Intent();
                galleryIntent.setType("image/*");
                galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(galleryIntent, "Seleziona una foto"), GALLERY_PICK);

            }
        });


@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == GALLERY_PICK && resultCode == RESULT_OK) {
            imageUri = data.getData();

            CropImage.activity()
                    .setGuidelines(CropImageView.Guidelines.ON)
                    .setAspectRatio(1, 1)
                    .start(this);

        }

        if(requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            CropImage.ActivityResult result = CropImage.getActivityResult(data);
            Uri resultUri = result.getUri();

                StorageReference filepath = mImageStorage.child("profile_images").child("1wq");

                filepath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                        if(task.isSuccessful()) {
                            Toast.makeText(ProfiloUtenteActivity.this, "Funziona", Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(ProfiloUtenteActivity.this, "Error", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            
        }
    } 
} 

共有1个答案

平学
2023-03-14

task失败时,它包含一个异常,该异常包含有关失败的更多信息。允许您找出问题原因的日志记录:

public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
    if(task.isSuccessful()) {
        Toast.makeText(ProfiloUtenteActivity.this, "Funziona", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(ProfiloUtenteActivity.this, "Error", Toast.LENGTH_SHORT).show();
        Log.e("Upload", "Upload failed", task.getException());
    }
}

一旦您收到错误消息,我建议您搜索它,因为很可能有人以前处理过它。

 类似资料:
  • 我试图在Firebase存储中使用Firebase上传图像,但文件不能完全上传。它只显示图像的大小9字节,下载时无法预览。 这是我使用的代码:- 我使用的反应本地图像作物选择器。我使用Firebase,但不是反应本机Firebase。请帮助!

  • 我使用的代码: 错误: C:\Users\Dell\PycharmProjects\ATF_TestOrder\venv\Scripts\python.exe C:/Users/Dell/PycharmProjects/ATF_TestOrder/ATF_TestOrder/ATF_TestOrder.py回溯(最后一次调用):driver.switch_至_frame(“上载映像”)文件第18行

  • 我正在尝试加载存储在应用程序文件夹上的图像当我打开活动时,我从logcat收到了这个错误: 1-20 01:30:40.125 14331-14331/mx.eusaga。af W/ImageView:无法打开内容:content://mx.eusaga.af.fileprovider/imagenes/1-db384fa8-f28b-4595-abbf-d45d38fd4036.jpgjava.

  • 我正在使用CKEditor插件将图像上传到我的OpenShift应用程序,但该应用程序不会上传文件。它在本地运行良好,但我无法确定是什么导致了这个问题。它似乎找不到目录。 == {err:{[Error: ENOENT, open'/var/lib/openShift/57cdb2770c1e660d0b000003/app-root/runtime/repo/路由来/.../Public/上传/

  • 我正在尝试使用服务号将图像文件上传到谷歌驱动器。 在服务号中,我遵循以下步骤: 1)在开发人员控制台上创建新项目 2)在API中 这里的上载失败,当我尝试调试代码时,我发现“request.ResponseBody”为null。 谁能帮我一下吗?

  • 我在Python中的Selenium webdriver上遇到了一个图像上传问题,我检查了HTML并使用完整的Xpath来定位元素,但没有工作。我仍然收到此错误selenium.common.exceptions.nosuchelementexception:消息:没有这样的元素:找不到元素:{“method”:“XPath”,“selector”:“/html/body/div[2]/div/d