获取意外的JDWP错误:103尝试使用改造上传图像到api服务器android?

Waq*_*qas 9 java android android-studio retrofit retrofit2

尝试使用改装多部件在api服务器上传图像时,我收到以下103错误消息,api收到api令牌,"_ method":"PUT"和图像url作为参数,响应时收到完整的JSON但是使用上一个或默认图像链接,当前所选图像不上传,其他一切都是可选的,任何帮助将不胜感激,代码列在下面谢谢.

主要的方法是POST,但"_method":"PUT"参数允许你上传图像,没有_method它变成一个POST消息和所有其他参数而不是强制,请检查图像.

com.sun.jdi.InternalException:意外的JDWP错误:103

接口:

public interface UserSignUpClient {

@POST("account")
Call<AuthenticationAccountCreationResponse> createAccount(@Body UserSignUp userSignUp);

@Multipart
@PUT("account")
Call<UserInfo> postImage(@Header("Authorization") String headerValue, @PartMap Map<String, String> map, @PartMap Map<String, File> imageMap, @Part MultipartBody.Part image);

@FormUrlEncoded
@POST("account")
Call<UserInfo> updateUser(@Header("Authorization") String headerValue, @FieldMap Map<String, String> map);
}
Run Code Online (Sandbox Code Playgroud)

改造生成器类:

public class RestClient {

private UserSignInClient userSignInClient;
private UserSignUpClient userSignUpClient;
private UserInfoClient userInfoClient;

public RestClient(String baseUrlLink){

    Gson gson = new GsonBuilder()
            .setLenient()
            .create();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrlLink)
            .addConverterFactory(GsonConverterFactory.create(gson)).build();

    if (baseUrlLink.equals(CONSTS.BASE_URL_ADDRESS_TOKEN)){

        userSignInClient = retrofit.create(UserSignInClient.class);
    } else if (baseUrlLink.equals(CONSTS.BASE_URL_ADDRESS_ACCOUNT_CREATION)) {

        userSignUpClient = retrofit.create(UserSignUpClient.class);
    } else if (baseUrlLink.equals(CONSTS.BASE_URL_ADDRESS_USER_INFO)){

        userInfoClient = retrofit.create(UserInfoClient.class);
    }
}

public UserSignInClient getUserSignInClient() {
    return userSignInClient;
}

public UserSignUpClient getUserSignUpClient() {
    return userSignUpClient;
}

public UserInfoClient getUserInfoClient() {
    return userInfoClient;
}
}
Run Code Online (Sandbox Code Playgroud)

主类:

userImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            galleryIntent.setType("*/*");
            startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
        }
    });

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK && null != data) {

        Uri selectedImageUri = data.getData();
        String filePath = FileUtils.getPath(this, selectedImageUri);
        file = new File(filePath);
        image_name = file.getName();

        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.READ_CONTACTS)
                != PackageManager.PERMISSION_GRANTED) {

            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

            } else {

                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
            }
        }
    }
}

@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {

            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                StringBuilder stringBuilder = new StringBuilder(AUTHORIZATION);

                sharedPreferences = this.getSharedPreferences(getResources().getString(R.string.token), 0);
                stringBuilder.append(sharedPreferences.getString(getResources().getString(R.string.token), ""));

                RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
                MultipartBody.Part body = MultipartBody.Part.createFormData("image", file.getName(), requestBody);

                UserUpdate userUpdate = new UserUpdate(file);

                methodMap.put("_method","PUT");
                imageMap.put("image", file);

                Call<UserInfo> uploadImage = new RestClient(CONSTS.BASE_URL_ADDRESS_ACCOUNT_CREATION).getUserSignUpClient()
                        .postImage(stringBuilder.toString(), methodMap, imageMap, body);

                uploadImage.enqueue(new Callback<UserInfo>() {
                    @Override
                    public void onResponse(Call<UserInfo> call, Response<UserInfo> response) {

                        if (response.isSuccessful()) {

                            Picasso.with(DetailActivity.this).load("http://ec2-35-161-195-128.us-west-2.compute.amazonaws.com/" + response.body().getImage()).into(userImage);

                        }
                    }

                    @Override
                    public void onFailure(Call<UserInfo> call, Throwable t) {

                        Toast.makeText(DetailActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });

            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}

        }
        return;
    }

    // other 'case' lines to check for other
    // permissions this app might request
}
}
Run Code Online (Sandbox Code Playgroud)

postman api image = https://i.imgur.com/AoCFZI6.png

Mr.*_*ard 6

我认为您的问题是您忘记向改装对象添加呼叫适配器.在你的RestClient课堂上,你必须这样:

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrlLink)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
Run Code Online (Sandbox Code Playgroud)

您还需要在内部添加此依赖项build.gradle:

compile "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
Run Code Online (Sandbox Code Playgroud)

我希望它有所帮助.

干杯.

  • 这个适配器是做什么的? (2认同)