我正在使用以下服务接口
在android中使用文件上传进行改造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);
}
这是我的服务生成器类
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);
}
}
这就是我在我的活动中调用服务的方式
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();
}
});
我收到以下错误:
java.net.SocketException: sendto failed: EPIPE (Broken pipe)
sendto failed: EPIPE (Broken pipe)
请帮我解决这个问题