我正在尝试使用okclient包将文件从android应用程序上传到restapi服务
但我得到了这个错误
错误:找不到symbol.settype(multipartbody.form)symbol:variable multipartbody 位置:xxclass
代码:
public void run(String urll, String fpath) throws Exception {
MediaType MEDIA_TYPE_PNG = MediaType.parse("text/csv");
// Use the imgur image upload API as documented at https://api.imgur.com/endpoints/image
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "square.csv",RequestBody.create(MediaType.parse("multipart/form-data"),
new File(fpath)))
.build();
Request request = new Request.Builder()
.url(getAbsoluteUrl(urll))
.post(requestBody)
.build();
try (Response response = client1.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
System.out.println(response.body().string());
}
}
我用的是okhttp3软件包- implementation 'com.squareup.okhttp3:okhttp:4.9.0'
但我仍然面临同样的问题,知道吗?
参考链接:https://www.baeldung.com/guide-to-okhttp
暂无答案!
目前还没有任何答案,快来回答吧!