I am trying to send a POST request on web server with Android Annotations REST Api, and I am trying to send an image as a Base64 String and video as a file. The operation also needs a Bearer Auth but I have managed that without an error.
My RestClient interface is like this:
@Rest(rootUrl = NetworkConstants.BASE_URL, converters = {GsonHttpMessageConverter.class, StringHttpMessageConverter.class,
FormHttpMessageConverter.class},interceptors = {
HeadersRequestInterceptor.class })
public interface RestClient extends RestClientHeaders {
@Post(NetworkConstants.UPLOAD_URL)
VideoUploadResponse uploadVideo(MultiValueMap<String,Object> model);
}
And my Request is like this:
MultiValueMap dataMultiPart = new LinkedMultiValueMap<>();
File file = new File(path);
dataMultiPart.add("thumbnail", bitmapString);
dataMultiPart.add("media", new FileSystemResource(file));
try {
VideoUploadResponse resonse = restClient.uploadVideo(dataMultiPart);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
In my interceptor class I have tried both this
public class HeadersRequestInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().add("content-type", MediaType.MULTIPART_FORM_DATA_VALUE);
request.getHeaders().add("authorization", "Bearer sometokenvalue");
return execution.execute(request, body);
}
}
and this
public class HeadersRequestInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().setContentType(MediaType.MULTIPART_FORM_DATA);
request.getHeaders().add("authorization", "Bearer sometokenvalue");
return execution.execute(request, body);
}
}
And I am getting the exception Invalid token character ' ' in token "json charset=UTF-8" everytime.
At first I thought there might be a problem with the auth token, but there is not.And when I try this request with postman there is no such error.
What am I doing wrong?