본문 바로가기
안드로이드+자바

Firebase storage 사용할 때 주의사항!!

by 문자메일 2017. 1. 15.

1. 메니페스트에 저장소 권한 줄것!


<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


2. 파일의 경로는 휴대폰... 피씨로 착각하지 말것...

InputStream stream = null;
try {
stream = new FileInputStream(new File("/storage/emulated/0/Pictures/KakaoTalk/1484276153455.JPEG"));
uploadTask = imageReference.putStream(stream);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
Uri downloadUrl = taskSnapshot.getDownloadUrl();
}
});
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(this, "예외발생!!!", Toast.LENGTH_SHORT).show();
}

3. 파이어베이스 Storage에서 권한 설정 반드시 할 것.... 이거 안해서 ....ㅠㅠ

service firebase.storage {

  match /b/realtimedatabase-3d54a.appspot.com/o {

    match /{allPaths=**} {

      allow read, write;

    }

  }

}

댓글