本文整理匯總了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();
}
}