use of java.net.FileNameMap in project portal by ixinportal.
the class OkHttpClientManager method guessMimeType.
// ****************************
// private Request buildMultipartFormRequest(String url, File[] files,
// String[] fileKeys, Param[] params)
// {
// // params = validateParam(params);
//
// MultipartBody.Builder builder = new MultipartBody.Builder()
// .setType(MultipartBody.FORM);
//
// for (Param param : params)
// {
// builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + param.key + "\""),
// RequestBody.create(null, param.value));
// }
// if (files != null)
// {
// RequestBody fileBody = null;
// for (int i = 0; i < files.length; i++)
// {
// File file = files[i];
// String fileName = file.getName();
// fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
// //TODO 根据文件名设置contentType
// builder.addPart(Headers.of("Content-Disposition",
// "form-data; name=\"" + fileKeys[i] + "\"; filename=\"" + fileName + "\""),
// fileBody);
// }
// }
//
// RequestBody requestBody = builder.build();
// return new Request.Builder()
// .url(url)
// .post(requestBody)
// .build();
// }
private String guessMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(path);
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
use of java.net.FileNameMap in project portal by ixinportal.
the class OkHttpClientManagerCallback method guessMimeType.
// ****************************
// private Request buildMultipartFormRequest(String url, File[] files,
// String[] fileKeys, Param[] params)
// {
// // params = validateParam(params);
//
// MultipartBody.Builder builder = new MultipartBody.Builder()
// .setType(MultipartBody.FORM);
//
// for (Param param : params)
// {
// builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + param.key + "\""),
// RequestBody.create(null, param.value));
// }
// if (files != null)
// {
// RequestBody fileBody = null;
// for (int i = 0; i < files.length; i++)
// {
// File file = files[i];
// String fileName = file.getName();
// fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
// //TODO 根据文件名设置contentType
// builder.addPart(Headers.of("Content-Disposition",
// "form-data; name=\"" + fileKeys[i] + "\"; filename=\"" + fileName + "\""),
// fileBody);
// }
// }
//
// RequestBody requestBody = builder.build();
// return new Request.Builder()
// .url(url)
// .post(requestBody)
// .build();
// }
private String guessMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(path);
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
use of java.net.FileNameMap in project portal by ixinportal.
the class OkHttpClientManagerSave method guessMimeType.
// ****************************
// private Request buildMultipartFormRequest(String url, File[] files,
// String[] fileKeys, Param[] params)
// {
// // params = validateParam(params);
//
// MultipartBody.Builder builder = new MultipartBody.Builder()
// .setType(MultipartBody.FORM);
//
// for (Param param : params)
// {
// builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + param.key + "\""),
// RequestBody.create(null, param.value));
// }
// if (files != null)
// {
// RequestBody fileBody = null;
// for (int i = 0; i < files.length; i++)
// {
// File file = files[i];
// String fileName = file.getName();
// fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
// //TODO 根据文件名设置contentType
// builder.addPart(Headers.of("Content-Disposition",
// "form-data; name=\"" + fileKeys[i] + "\"; filename=\"" + fileName + "\""),
// fileBody);
// }
// }
//
// RequestBody requestBody = builder.build();
// return new Request.Builder()
// .url(url)
// .post(requestBody)
// .build();
// }
private String guessMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(path);
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
use of java.net.FileNameMap in project portal by ixinportal.
the class OkHttpClientManagerSign method guessMimeType.
// ****************************
// private Request buildMultipartFormRequest(String url, File[] files,
// String[] fileKeys, Param[] params)
// {
// // params = validateParam(params);
//
// MultipartBody.Builder builder = new MultipartBody.Builder()
// .setType(MultipartBody.FORM);
//
// for (Param param : params)
// {
// builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + param.key + "\""),
// RequestBody.create(null, param.value));
// }
// if (files != null)
// {
// RequestBody fileBody = null;
// for (int i = 0; i < files.length; i++)
// {
// File file = files[i];
// String fileName = file.getName();
// fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
// //TODO 根据文件名设置contentType
// builder.addPart(Headers.of("Content-Disposition",
// "form-data; name=\"" + fileKeys[i] + "\"; filename=\"" + fileName + "\""),
// fileBody);
// }
// }
//
// RequestBody requestBody = builder.build();
// return new Request.Builder()
// .url(url)
// .post(requestBody)
// .build();
// }
private String guessMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(path);
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
use of java.net.FileNameMap in project portal by ixinportal.
the class OkHttpClientManagerTime method guessMimeType.
// ****************************
// private Request buildMultipartFormRequest(String url, File[] files,
// String[] fileKeys, Param[] params)
// {
// // params = validateParam(params);
//
// MultipartBody.Builder builder = new MultipartBody.Builder()
// .setType(MultipartBody.FORM);
//
// for (Param param : params)
// {
// builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + param.key + "\""),
// RequestBody.create(null, param.value));
// }
// if (files != null)
// {
// RequestBody fileBody = null;
// for (int i = 0; i < files.length; i++)
// {
// File file = files[i];
// String fileName = file.getName();
// fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
// //TODO 根据文件名设置contentType
// builder.addPart(Headers.of("Content-Disposition",
// "form-data; name=\"" + fileKeys[i] + "\"; filename=\"" + fileName + "\""),
// fileBody);
// }
// }
//
// RequestBody requestBody = builder.build();
// return new Request.Builder()
// .url(url)
// .post(requestBody)
// .build();
// }
private String guessMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(path);
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
Aggregations