我想将照片上载到
FirebaseStorage
,从我的设备中获取。如果照片位于设备上,则会在文件夹下创建它
/Photos/namefile.jpg
如果我从SD卡加载,它会提供所有路径
/Photos/storage/emulated/0/namefile.jpg
. 我想保存所有的数据
/照片/名称文件。jpg公司
这是我的代码:
if (requestCode==GALERY_INTENT &&resultCode==RESULT_OK){
final Uri uri = data.getData();
Log.d(TAG,uri.getLastPathSegment().toString());
Log.d(TAG,uri.toString());
StorageReference path = storeRef.child(uid).child("Photos").child(uri.getLastPathSegment());
path.putFile(uri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if(task.isSuccessful()){
}
}
});
更新
现在,它可以很好地使用以下代码:
final Uri uri = data.getData();
File file = new File(uri+"");
String [] segments = file.getName().split("[\\p{Punct}â]2F");
StorageReference path = storeRef.child(uid).child("Photos").child(segments[segments.length-1]);