我正在开发一个Android应用程序,并且正在尝试使用一个摄取图像的终结点,并将其保存到 Google Cloud Storage 中并返回URL。
这是我的用户服务界面中负责发出请求的部分:
@POST("/add")
Call<PhotoUrlGetter> getUrlForPhoto(@Body Uri media);
这是我实际发出请求的代码的一部分:
Uri media = ""; //the value is gotten from the image the user selected from gallery
UserService photoService = ServiceGeneratorForMedia.createService(UserService.class, "photoservice");
Call<PhotoUrlGetter> photoCall = photoService.getUrlForPhoto(media);
photoCall.enqueue(new Callback<PhotoUrlGetter>() {
@Override
public void onResponse(Call<PhotoUrlGetter> call, Response<PhotoUrlGetter> response) {
if(response.isSuccessful()){
Toast.makeText(getActivity().getApplicationContext(), response.body().getMediaUrl(), Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getActivity().getApplicationContext(), Integer.toString(response.code()), Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<PhotoUrlGetter> call, Throwable t) {
Toast.makeText(getActivity().getApplicationContext(), "Failed", Toast.LENGTH_LONG).show();
}
});