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


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";

    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()
                .setRequestInterceptor(new RequestInterceptor() {
                    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>() {

    public void success(Pk_Response pk_response, retrofit.client.Response response) {

    public void failure(RetrofitError error) {
        Log.e("Upload", "error");

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: