Home » Android » android – Broken Pipe exception (sendto failed: EPIPE (Broken pipe)) in retrofit

android – Broken Pipe exception (sendto failed: EPIPE (Broken pipe)) in retrofit

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am using retrofit for file uploading in android i’m using the following service interface

public interface FileUploadService {


    public static final String BASE_URL = "server url";

    @Multipart
    @POST("/upload")
    void upload(@Part("file") TypedFile file,
                @Part("path") String path,
                Callback<Pk_Response> cb);
}

This is my service generator class

public class ServiceGenerator {

    // No need to instantiate this class.
    private ServiceGenerator() {
    }


    public static <S> S createService(Class<S> serviceClass, String baseUrl) {

        RestAdapter.Builder builder = new RestAdapter.Builder()
                .setEndpoint(baseUrl)
                .setRequestInterceptor(new RequestInterceptor() {
                    @Override
                    public void intercept(RequestFacade request) {
                        request.addHeader("accesstoken", "token");                            request.addHeader("Content-Type", "multipart/form-data");
                    }
                })
                .setClient(new OkClient(new OkHttpClient()));

        RestAdapter adapter = builder.build();

        return adapter.create(serviceClass);
    }
}

This is how i am calling the service in my activity

FileUploadService service = ServiceGenerator.createService(FileUploadService.class, FileUploadService.BASE_URL);
    TypedFile typedFile = new TypedFile("image/jpeg", new File(outputFileUri.getPath()));
    String path = "directory11";

service.upload(typedFile, path, new Callback<Pk_Response>() {

    @Override
    public void success(Pk_Response pk_response, retrofit.client.Response response) {
        Toast.makeText(getApplicationContext(),"requestsuccess",Toast.LENGTH_LONG).show();
    }

    @Override
    public void failure(RetrofitError error) {
        Log.e("Upload", "error");
        error.toString();
    }
});

I’m getting the following error:

java.net.SocketException: sendto failed: EPIPE (Broken pipe)
sendto failed: EPIPE (Broken pipe)

Please help me on how to solve this issue

How to&Answers: