0

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();
                            }
                        });
                }
            }
        );
    }

1 Answer 1

1

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"));
Sign up to request clarification or add additional context in comments.

2 Comments

Ok thank you for your answer ,I'll check it.The problem is that the file it hasn't the same name .The final name it takes it from that: public final String FILE_NAME=dateFormat.format(date)+".txt";
yep, that last line of code is from the official doc, you should change it with the path of your file

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.