简体   繁体   English

Android的 - 如何存储这已经创造了公司的FireStore文件夹中的图像

[英]Android - How to store an image inside the Firestore folder which is already created

public void upload() {
    if(imageUri!=null) {
        StorageReference reference=storageReference.child("customers/");
        reference.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                // Toast.makeText(getApplicationContext(),"File Uploaded",Toast.LENGTH_LONG).show();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show();
            }
        }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                double totalProgress=(100*taskSnapshot.getBytesTransferred())/taskSnapshot.getTotalByteCount();
                // Toast.makeText(getApplicationContext(),"File uploaded"+(int)totalProgress,Toast.LENGTH_LONG).show();
            }
        });
    }
}

In Firebase storage, there is one folder called "customers" where I want to store the selected image. 在Firebase存储中,有一个名为“客户”的文件夹,我想在其中存储所选图像。 When I try to upload the image, it is storing it as a different folder, not the folder which is already created. 当我尝试上传的图片,它是把它作为一个不同的文件夹,而不是它已经创建的文件夹。 Here, "customers" is the already created folder. 在这里,“客户”是已经创建的文件夹。

Try to get file from this file, it could be because of incorrect reference to your folder. 尝试从此文件中获取文件,这可能是因为对您的文件夹的引用不正确。 Also show code where is your getReference() method is called or it is better how you set reference to your FirebaseStorage. 还显示代码,在何处调用getReference()方法,或者更好地设置对FirebaseStorage的引用。

public void upload(String imageName) {
    if(imageUri!=null) {
        StorageReference reference=storageReference.child("customers).child(imageName);
        reference.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                // Toast.makeText(getApplicationContext(),"File Uploaded",Toast.LENGTH_LONG).show();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show();
            }
        }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
                double totalProgress=(100*taskSnapshot.getBytesTransferred())/taskSnapshot.getTotalByteCount();
                // Toast.makeText(getApplicationContext(),"File uploaded"+(int)totalProgress,Toast.LENGTH_LONG).show();
            }
        });
    }
}

In order to retrieve the image name use:- 为了检索图像名称,请使用:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        Uri selectedImageUri = data.getData( );
        String picturePath = getPath( getActivity( ).getApplicationContext( ), selectedImageUri );
        Log.d("Picture Path", picturePath);
        upload(picturePath);

    }
}

public static String getPath( Context context, Uri uri ) {
    String result = null;
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver( ).query( uri, proj, null, null, null );
    if(cursor != null){
        if ( cursor.moveToFirst( ) ) {
            int column_index = cursor.getColumnIndexOrThrow( proj[0] );
            result = cursor.getString( column_index );
        }
        cursor.close( );
    }
    if(result == null) {
        result = "Not found";
    }
    return result;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android中将包含对象的对象存储到Firestore? - How do I store an object which contains an object to Firestore in Android? 如何在Android的Firestore中存储bigdecimal - how to store bigdecimal in firestore in Android 如何将图像从Drawable文件夹存储到Android中的SDCard? - How to Store Image from Drawable folder to SDCard in Android? 如何获取 zip 文件内的文件夹内的图像文件的大小 - How to get a size of a image file which is inside a folder which is inside a zip file Android - 如何在Firestore中显示已创建的用户 - Android - How to show created user in Firestore 如何以编程方式打开我在我的应用程序中在 Android 中创建的文件夹? - How to open folder which I have created in my app in Android programmatically? Android:是否可以将图像上传到服务器内部的文件夹中? - Android: is it possible to upload an image on a folder inside a server? 将图像保存在特定的文件夹内,并将路径存储在mysql中,以便以后显示 - Save image inside specific folder and store path in mysql to display later Android 如何拒绝已经存在的权限 - Android how to deny the permission which is already 如何将多个图像的 downloadUrl 存储到 Firebase Firestore ? 无法在 Firestore 文档中的多个字段中创建和存储 - How do I store downloadUrl of multiple images to the Firebase Firestore ? Unable to create and store inside multiple fields inside Firestore document
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM