Edward M
Edward M

Reputation: 83

Problem to upload file from my app to Firebase

Hi I have problem with uploading file to Firebase from my app.I am following the Android studio firebase assistant to create it but it doesn't work and it print me the text from failure function. Also at Logcat it's printed this:

An unknown error occurred, please check the HTTP result code and inner exception for server response. Code: -13000 HttpResult: 0 2018-12-20 23:07:23.680 30476-30564/com.example.johny.test E/StorageException: /storage/emulated/0 (Is a directory) java.io.FileNotFoundException: /storage/emulated/0 (Is a directory)

for the line riversRef.putFile(files) from below code

Thank you for your time

upload.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view){

                try {
                    File file=new File(Environment.getExternalStorageDirectory().getAbsolutePath(),FILE_NAME);
                    nameoffile=FILE_NAME;
                    FileOutputStream fos=new FileOutputStream (file);
                    DataOutputStream dout = new DataOutputStream(fos);
                    //dout.writeInt(SignalData.size()); // Save line count
                    for(int i=0;i<SignalData.size();i++){
                        dout.writeChars(SignalData.get(i));
                    }
                    dout.close(); // ... and close.
                    //Toast.makeText(getActivity(),"File Successful Created",Toast.LENGTH_LONG).show();
                } catch (IOException exc) {
                    exc.printStackTrace();
                    Toast.makeText(getActivity(),"File NOT Created",Toast.LENGTH_LONG).show();
                }


                Uri files = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath()));
                StorageReference riversRef = mStorageRef.child(nameoffile);

                riversRef.putFile(files)
                        .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                            @Override
                            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                                // Get a URL to the uploaded content
                                Toast.makeText(getActivity(),"File Upload Successfully",Toast.LENGTH_LONG).show();
                            }
                        })
                        .addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception exception) {
                                // Handle unsuccessful uploads
                                // ...
                                Toast.makeText(getActivity(),"File Didn't Upload",Toast.LENGTH_LONG).show();
                            }
                        });
                }
            }
        );
    }

Upvotes: 0

Views: 1089

Answers (1)

Gast&#243;n Saill&#233;n
Gast&#243;n Saill&#233;n

Reputation: 13129

E/StorageException: /storage/emulated/0 (Is a directory) java.io.FileNotFoundException: /storage/emulated/0 (Is a directory)

As the error states, you are refering to a directory here, not a file

Uri files = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath()));

check the path from where are you trying to find the file and change it.

From Firebase Storage documentation, you can find examples there on how to find your file.

You can also specify where your file is like this

Uri file = Uri.fromFile(new File("path/to/images/rivers.jpg"));

Upvotes: 1

Related Questions