[英]how to get image path as a string and save it to a server
I am working on a project that needs to save user's information including the profile image to the server using retrofit.我正在开发一个需要使用 retrofit 将用户信息(包括配置文件图像)保存到服务器的项目。 the backend was built with java spring boot and the profile image was declared as a string in the backend.后端是使用 java spring 引导构建的,并且配置文件图像在后端声明为字符串。 I want to pick an image from my gallery by using a crop image and save the image to the server so that I can retrieve it anytime from the server and upload it when the user logins.我想通过使用裁剪图像从我的图库中选择图像并将图像保存到服务器,以便我可以随时从服务器检索它并在用户登录时上传它。 I am still a beginner in android app development so I don't know how to go about that.我仍然是 android 应用程序开发的初学者,所以我不知道如何了解 go。 I have picked and cropped the image successfully but the image path cannot be formatted to a string that can be stored and retrieved anytime.我已成功选择并裁剪图像,但图像路径无法格式化为可以随时存储和检索的字符串。 I really need help here.我在这里真的需要帮助。 Thanks谢谢
Here is the code.
imagePicker.setOnClickListener(view -> {
CropImage.activity()
.setAspectRatio(1,1)
.start(PatientRegistrationActivity.this);
});
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE && resultCode==RESULT_OK && data !=null){
CropImage.ActivityResult result = CropImage.getActivityResult(data);
Uri profileImageUri = result.getUri();
profilePicture.setImageURI(profileImageUri);//profilePicture here is imageview that displays the picked image from the gallery
String imagePath= profileImageUri.getPath();
Log.d("Main","Your image path is "+imagePath);
}else {
Toast.makeText(PatientRegistrationActivity.this,"Error Occurred, Please try Again",Toast.LENGTH_SHORT).show();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.