我正在尝试进行多部分重新设置,但无论我做什么,我都会得到相同的错误。我想我错过了什么,请指出我。这是有关请求的所有代码: 1.接口类
public interface ApiInterface{
@Multipart
@POST("/api/v1/ads")
retrofit.client.Response updateProfileWithImage(
@Part("user_token") TypedString ut,
@Part("apikey") TypedString ke,
@Part("title") TypedString ti,
@Part("description") TypedString de,
@Part("id_location") TypedString lo,
@Part("id_category") TypedString ca,
@Part("phone") TypedString ph,
@Part("price") TypedString pr,
@PartMap Map<String,TypedFile> Files
);
}
OnCreate活动。图像路径形式为/ sdcard /.....
RestAdapter adapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.FULL)
.setEndpoint("http://website.com")
.build();
ApiInterface apiInterface = adapter.create(ApiInterface.class);
TypedString ut = new TypedString(utoken);
TypedString ke = new TypedString(apikey);
TypedString ti = new TypedString(tite);
TypedString de = new TypedString(dese);
TypedString lo = new TypedString(idloc);
TypedString ca = new TypedString(idcat);
TypedString ph = new TypedString(phono);
TypedString pr = new TypedString(prici);
Map<String, TypedFile> files = new HashMap<String, TypedFile>();
files.put("image", new TypedFile("image/jpg", new File(fii)));
//here i get retrofiterror talking about rest adapter
retrofit.client.Response response = apiInterface.updateProfileWithImage(ut, ke, ti, de, lo, ca, ph, pr, files);
我即将死于此我遭受了很多苦难,请帮帮我
更新: 通过在新线程中运行代码解决了错误,但仍未上传图像,请帮忙。这是新线程的人:
new Thread(new Runnable(){
@Override
public void run() {
try {
//but all retrofit code here
} catch (Exception ex) {
ex.printStackTrace();
}
}
}).start();