I (Henüz 2.0.x için hareket edemez)Uyarlama 1.9.x
Ben This Post okudum Retrofitler 1.9.x kullanarak bir FileInputStream POST çalışıyorum bir FileInputStream deftere nakil.
Bu yazımda, arayüzümde bir TypedInput kullanırsam ve akışı işleyen TypedInput sınıf sarıcısını kullanırsam, bunun işe yaradığını anladım. TypedInput ve TypedOutput'ın yanıtı (TypedInput en doğru ses çıktıysa, bağdaştırılmış retrofit belgelerinin söyleyebildiğim kadarını belirtmediyse de açık değil) Ayrıca,
Devam etmek için - sınıf
private class InputStreamMunger implements TypedInput {
private InputStream is;
private String mimeType;
private Long fileLength;
public InputStreamMunger(InputStream is, String mimeType, Long fileLength) {
this.is = is;
this.fileLength = fileLength;
this.mimeType = mimeType;
}
@Override
public String mimeType() {
return mimeType;
}
@Override
public long length() {
return fileLength;
}
@Override
public InputStream in() throws IOException {
return is;
}
}
Benim Arayüz:
@Multipart
@POST("/MrService/v1/upload/{accountId}")
Response upload(
@Path("accountId") String accountId,
@Part("file") TypedInput file);
Sonra
FileInputStream is = new FileInputStream("src/test/java/com/me/MrService/tester.txt");
InputStreamMunger file ;
try {
file = new InputStreamMunger(is, "text/plain", is.getChannel().size());
} catch (IOException e) {
e.printStackTrace();
return;
}
Response r = client.upload("12345", file);
diyoruz 363.210
i almak hatadır:
retrofit.RetrofitError: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.me.MrService.IntegrationTestIT$InputStreamMunger and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS))
bu bir Sohbet işlemek için kendi mapper oluşturmak gerektiğini ifade ediyor mu? Umarım sadece yanlış bir şey yapıyorum ve bu kasnağa atlamaya ihtiyacım yok.
Teşekkürler!