android okhttp上传文件mediatype有哪些
展开全部
/**
* @param mediaType MediaType
* @param uploadUrl put请求地址
* @param localPath 本地文件路径
* @return 响应的结果 和 HTTP status code
* @throws IOException
*/
public String put(MediaType mediaType, String uploadUrl, String localPath) throws IOException {
File file = new File(localPath);
RequestBody body = RequestBody.create(mediaType, file);
Request request = new Request.Builder()
.url(uploadUrl)
.put(body)
.build();
Response response = client.newCall(request).execute();
return response.code()+ ":" + response.body().string() ;
}
//上传JPG图片
public String putImg(String uploadUrl, String localPath) throws IOException {
MediaType Image = MediaType.parse("image/jpeg; charset=utf-8");
* @param mediaType MediaType
* @param uploadUrl put请求地址
* @param localPath 本地文件路径
* @return 响应的结果 和 HTTP status code
* @throws IOException
*/
public String put(MediaType mediaType, String uploadUrl, String localPath) throws IOException {
File file = new File(localPath);
RequestBody body = RequestBody.create(mediaType, file);
Request request = new Request.Builder()
.url(uploadUrl)
.put(body)
.build();
Response response = client.newCall(request).execute();
return response.code()+ ":" + response.body().string() ;
}
//上传JPG图片
public String putImg(String uploadUrl, String localPath) throws IOException {
MediaType Image = MediaType.parse("image/jpeg; charset=utf-8");
展开全部
1. /**
* @param mediaType MediaType
* @param uploadUrl put请求地址
* @param localPath 本地文件路径
* @return 响应的结果 和 HTTP status code
* @throws IOException
*/
public String put(MediaType mediaType, String uploadUrl, String localPath) throws IOException {
File file = new File(localPath);
RequestBody body = RequestBody.create(mediaType, file);
Request request = new Request.Builder()
.url(uploadUrl)
.put(body)
.build();
Response response = client.newCall(request).execute();
return response.code()+ ":" + response.body().string() ;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询