本文整理汇总了Java中play.mvc.Http.MultipartFormData方法的典型用法代码示例。如果您正苦于以下问题:Java Http.MultipartFormData方法的具体用法?Java Http.MultipartFormData怎么用?Java Http.MultipartFormData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.mvc.Http
的用法示例。
在下文中一共展示了Http.MultipartFormData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importGrades
import play.mvc.Http; //导入方法依赖的package包/类
@Restrict({@Group("ADMIN"), @Group("TEACHER")})
public Result importGrades() {
Http.MultipartFormData<File> body = request().body().asMultipartFormData();
Http.MultipartFormData.FilePart<File> filePart = body.getFile("file");
if (filePart == null) {
return notFound();
}
File file = filePart.getFile();
User user = getLoggedUser();
boolean isAdmin = user.hasRole(Role.Name.ADMIN.toString(), getSession());
try {
CsvBuilder.parseGrades(file, user, isAdmin ? Role.Name.ADMIN : Role.Name.TEACHER);
} catch (IOException e) {
Logger.error("Failed to parse CSV file. Stack trace follows");
e.printStackTrace();
return internalServerError("sitnet_internal_error");
}
return ok();
}
示例2: upload
import play.mvc.Http; //导入方法依赖的package包/类
public Result upload() {
// Get the current logged in user
User user = User.find.byId(Long.parseLong(session().get("uid")));
// Process form submission as multipart form data
Http.MultipartFormData body = request().body().asMultipartFormData();
UserUpload userUpload = null;
for (Object obj : body.getFiles()) {
Http.MultipartFormData.FilePart filePart = (Http.MultipartFormData.FilePart) obj;
userUpload = uploadFile(filePart, user);
}
if (userUpload != null) {
return ok("{ 'filename' : " + userUpload.getFileName() + "}");
} else {
return internalServerError("{ }");
}
}
示例3: deployWorkflows
import play.mvc.Http; //导入方法依赖的package包/类
@Restrict({@Group("ADMIN")})
public Result deployWorkflows() {
Http.MultipartFormData body = request().body().asMultipartFormData();
Http.MultipartFormData.FilePart filePart = body.getFile("filename");
if (filePart != null) {
ConfigManager configManager = ConfigManager.getInstance();
char[] keystorePassword = ConfigFactory.defaultApplication().getString("keystore.password").toCharArray();
String keystoreLocation = ConfigFactory.defaultApplication().getString("keystore.location");
try {
File zipFile = (File) filePart.getFile();
WorkflowPackageVerifier verifier = new WorkflowPackageVerifier();
verifier.checkIntegrity(zipFile, keystoreLocation, keystorePassword);
configManager.unpack((File) filePart.getFile());
} catch (Exception e) {
flash("error", "Could not verify package.");
return redirect(routes.Workflows.deploy());
}
flash("message", "Packages zip file was successfully deployed");
return redirect(routes.Workflows.deploy());
} else {
flash("error", "Missing file");
return badRequest();
}
}