当前位置: 首页>>代码示例>>Java>>正文


Java MultipartFormData.getFile方法代码示例

本文整理汇总了Java中play.mvc.Http.MultipartFormData.getFile方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartFormData.getFile方法的具体用法?Java MultipartFormData.getFile怎么用?Java MultipartFormData.getFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在play.mvc.Http.MultipartFormData的用法示例。


在下文中一共展示了MultipartFormData.getFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: submit

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
public Result submit() {
    User user = User.findByEmail(session().get("email"));
    Form<UserProfile> filledForm = profileForm.bindFromRequest();

    if (filledForm.hasErrors()) {
        return badRequest(createprofile.render(filledForm));
    } else {
        MultipartFormData body = request().body().asMultipartFormData();
        FilePart picture = body.getFile("image");
        UserProfile newProfile = filledForm.get();
        newProfile.image = picture.getFile();
        String filePath = "public/user_pictures/"+ user.email + ".png";
        newProfile.saveImage(picture.getFile(), filePath);
        newProfile.userId = user.id;
        newProfile.save();
        return ok(viewprofile.render(user, newProfile));
    }
}
 
开发者ID:vn09,项目名称:rental-helper,代码行数:19,代码来源:CreateProfile.java

示例2: guardarArchivo

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
public static Result guardarArchivo() {
    MultipartFormData body = request().body().asMultipartFormData();
    FilePart fichero = body.getFile("archivo");
    
    String nombreFichero = fichero.getFilename();
    int indice = nombreFichero.lastIndexOf(".");
    String type = nombreFichero.substring(indice + 1, nombreFichero.length());
    
    if(indice != -1)
        nombreFichero = nombreFichero.substring(0,indice);
    
    String tipo = fichero.getContentType();

    File file = fichero.getFile();
    File newFile = new File("public/data/" + nombreFichero + "."+ type);
    try {
        Files.copy(file, newFile);
        
    } catch (IOException e) {
        e.printStackTrace();
    }
    return index();
}
 
开发者ID:Arquisoft,项目名称:ObservaTerra42,代码行数:24,代码来源:Application.java

示例3: uploadExcel

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
public static Result uploadExcel() {
try {
  MultipartFormData body = request().body().asMultipartFormData();
  FilePart excel = body.getFile("excel");
  if (excel != null) {
	    File file = excel.getFile();
	    ExcelReader reader = new ExcelReader();
	    List<Observation> obsList = reader.read(new FileInputStream(file));
	    for (Observation obs: obsList) {
	    	obs.save();
	    }
	    Logger.info("Excel file uploaded with " + obsList.size() + " observations");
	    return redirect(routes.Application.index());
   } else {
    	Logger.error("Missing file to upload ");
	    return redirect(routes.Application.index());    
   } 
  }
catch (IOException e) {
  return(badRequest(Messages.get("read.excel.error") + "." + e.getLocalizedMessage()));	
}
}
 
开发者ID:Arquisoft,项目名称:ObservaTerra42,代码行数:23,代码来源:API.java

示例4: uploadExcel

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
@Security.Authenticated(SecuredController.class)
public static Result uploadExcel() {
    MultipartFormData body = request().body().asMultipartFormData();
    FilePart picture = body.getFile("excelFile");
    if(picture != null) {
        String fileName = picture.getFilename();
        String contentType = picture.getContentType();
        File file = picture.getFile();
        Logger.info("Uploaded " + fileName);
        try {
            excelParser(file);
            flash("success", "File " + fileName + " uploaded");
        }
        catch(Throwable e) {
            flash("error", "File " + fileName + " parse errors:");
            flash("error_log", e.getMessage());
            e.printStackTrace();
        }
        return redirect(routes.TargetController.upload());
    }
    else {
        Logger.info("Upload failed ");
        flash("error", "Missing file");
        return redirect(routes.TargetController.upload());
    }
}
 
开发者ID:ukwa,项目名称:w3act,代码行数:27,代码来源:TargetController.java

示例5: addAttachmentToQuestion

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result addAttachmentToQuestion() {

    MultipartFormData<File> body = request().body().asMultipartFormData();
    FilePart<File> filePart = body.getFile("file");
    if (filePart == null) {
        return notFound();
    }
    File file = filePart.getFile();
    if (file.length() > AppUtil.getMaxFileSize()) {
        return forbidden("sitnet_file_too_large");
    }
    Map<String, String[]> m = body.asFormUrlEncoded();
    Long qid = Long.parseLong(m.get("questionId")[0]);
    Question question = Ebean.find(Question.class)
            .fetch("examSectionQuestions.examSection.exam.parent")
            .where()
            .idEq(qid)
            .findUnique();
    if (question == null) {
        return notFound();
    }
    String newFilePath;
    try {
        newFilePath = copyFile(file, "question", qid.toString());
    } catch (IOException e) {
        return internalServerError("sitnet_error_creating_attachment");
    }
    // Remove existing one if found
    removePrevious(question);

    Attachment attachment = createNew(filePart, newFilePath);

    question.setAttachment(attachment);
    question.save();

    return ok(attachment);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:39,代码来源:AttachmentController.java

示例6: addAttachmentToExam

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
@Restrict({@Group("TEACHER"), @Group("ADMIN")})
public Result addAttachmentToExam() {
    MultipartFormData<File> body = request().body().asMultipartFormData();
    FilePart<File> filePart = body.getFile("file");
    if (filePart == null) {
        return notFound();
    }
    File file = filePart.getFile();
    if (file.length() > AppUtil.getMaxFileSize()) {
        return forbidden("sitnet_file_too_large");
    }
    Map<String, String[]> m = body.asFormUrlEncoded();
    Long eid = Long.parseLong(m.get("examId")[0]);
    Exam exam = Ebean.find(Exam.class, eid);
    if (exam == null) {
        return notFound();
    }
    User user = getLoggedUser();
    if (!user.hasRole(Role.Name.ADMIN.toString(), getSession()) && !exam.isOwnedOrCreatedBy(user)) {
        return forbidden("sitnet_error_access_forbidden");
    }
    String newFilePath;
    try {
        newFilePath = copyFile(file, "exam", eid.toString());
    } catch (IOException e) {
        return internalServerError("sitnet_error_creating_attachment");
    }
    // Delete existing if exists
    removePrevious(exam);

    Attachment attachment = createNew(filePart, newFilePath);
    exam.setAttachment(attachment);
    exam.save();
    return ok(attachment);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:36,代码来源:AttachmentController.java

示例7: submit

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
public Result submit() {
    User user = User.findByEmail(session().get("email"));
    Form<UserProfile> filledForm = profileForm.bindFromRequest();
    if (filledForm.hasErrors()) {
        return badRequest(editprofile.render(user, profileForm));
    } else {
        MultipartFormData body = request().body().asMultipartFormData();
        FilePart picture = null;
        if (body != null && body.getFile("image") != null) {
            picture = body.getFile("image");
        }
        UserProfile profile = null;
        if (user != null) {
            profile = UserProfile.findByUserId(user.id);
        } else {
            profile = UserProfile.findByUserId(filledForm.get().userId);
        }
        profile.set(filledForm.get());
        if (picture != null && picture.getFile() != null) {
            profile.image = picture.getFile();
            String filePath = "public/user_pictures/" + user.email + ".png";
            profile.saveImage(picture.getFile(), filePath);
        }
        profile.save();
        return GO_VIEW;
    }
}
 
开发者ID:vn09,项目名称:rental-helper,代码行数:28,代码来源:EditProfile.java

示例8: hasFileField

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
/**
 * Return true if the specified form contains a valid file field.
 * 
 * @param fieldName
 *            the field name
 * 
 * @return a boolean
 */
public static boolean hasFileField(String fieldName) {

    boolean r = false;

    MultipartFormData body = Controller.request().body().asMultipartFormData();
    if (body != null) {

        FileType fileType = getFileType(fieldName);
        String fileFieldName = getFileInputName(fieldName, fileType);

        switch (fileType) {
        case UPLOAD:
            if (body.getFile(fileFieldName) != null) {
                r = true;
            }
            break;
        case URL:
            if (body.asFormUrlEncoded().get(fileFieldName)[0] != null && !body.asFormUrlEncoded().get(fileFieldName)[0].equals("")) {
                r = true;
            }
            break;
        }
    }

    return r;
}
 
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:35,代码来源:FileAttachmentHelper.java

示例9: getFilePart

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
/**
 * Get the file part of the attachment for UPLOAD type.
 * 
 * @param fieldName
 *            the field name
 */
public static FilePart getFilePart(String fieldName) {

    FileType fileType = getFileType(fieldName);

    if (fileType.equals(FileType.UPLOAD)) {
        MultipartFormData body = Controller.request().body().asMultipartFormData();
        FilePart filePart = body.getFile(getFileInputName(fieldName, fileType));
        return filePart;
    }

    return null;

}
 
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:20,代码来源:FileAttachmentHelper.java

示例10: createTempAvatar

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
/**
 * Handles the upload of the temporary avatar image
 *
 * @param id
 * @return
 */
public Result createTempAvatar(Long id) {

    Account account = accountManager.findById(id);

    if (account == null) {
        return notFound();
    }

    ObjectNode result = Json.newObject();
    MultipartFormData body = request().body().asMultipartFormData();

    if (body == null) {
        result.put("error", "No file attached");
        return badRequest(result);
    }

    MultipartFormData.FilePart avatar = body.getFile("avatarimage");

    if (avatar == null) {
        result.put("error", "No file with key 'avatarimage'");
        return badRequest(result);
    }

    try {
        avatarManager.setTempAvatar(avatar, account.id);
    } catch (ValidationException e) {
        result.put("error", e.getMessage());
        return badRequest(result);
    }

    result.put("success", getTempAvatar(id).toString());
    return ok(result);
}
 
开发者ID:socia-platform,项目名称:htwplus,代码行数:40,代码来源:ProfileController.java

示例11: uploadFile

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
/**
 * Handles the file upload.
 * @throws OWLOntologyCreationException 
 * @throws InterruptedException 
 */
public static Result uploadFile() throws OWLOntologyCreationException, InterruptedException {
	
	Form<Ontology> ontologyForm = form(Ontology.class);
	
	MultipartFormData body = request().body().asMultipartFormData();
	  FilePart ontologyFile = body.getFile("ontology");
	  if (ontologyFile != null) {
	   String fileName = ontologyFile.getFilename();
	   String contentType = ontologyFile.getContentType(); 
	   // ontology.get
	   File file = ontologyFile.getFile();
	    
	   try{ 
		   loadOntology(file.getPath());
	   }
	   catch(UnparsableOntologyException ex){
		   return ok(index.render("Not a valid Ontology File"));
	   }
	  
	  //Initiate the reasoner to classify ontology
	  if (BeeOntologyfile.exists())
	  {
		reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
		
		//System.out.println("suppp");
		loadBeeCharacteristics();	
	  }
	    
	  Ontology ontology = new Ontology(KeyDescriptionArraylist, null, null);
	  return ok(view.render(ontology.features));
	    
	  } else {
	    flash("error", "Missing file");
	    return ok(index.render("File Not Found"));	
	  }
}
 
开发者ID:jembi,项目名称:woc,代码行数:42,代码来源:Application.java

示例12: importFeatures

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
public static Result importFeatures(String name){
	DynamicForm form = form().bindFromRequest();
	Logger.info("PARAMETERS : " + form.data().toString());
	String table1Name = form.get("table1_name");
	String table2Name = form.get("table2_name");

	MultipartFormData body = request().body().asMultipartFormData();
	FilePart fp = body.getFile("csv_file_path");

	if (fp != null) {
		String fileName = fp.getFilename();
		String contentType = fp.getContentType();
		Logger.info("fileName: " + fileName + ", contentType: " + contentType);
		File file = fp.getFile();
		Project project = ProjectDao.open(name);

		try{
			Table table1 = TableDao.open(name, table1Name);
			Table table2 = TableDao.open(name, table2Name);
			List<Feature> features = RuleDao.importFeaturesFromCSVWithHeader(project,
					table1, table2, file.getAbsolutePath());
			// save the features - this automatically updates and saves the project
			System.out.println(features);
			System.out.println(name);
			RuleDao.save(name, features);
			ProjectController.statusMessage = "Successfully imported " + features.size() + " features.";
		}
		catch(IOException ioe){
			flash("error", ioe.getMessage());
			ProjectController.statusMessage = "Error: " + ioe.getMessage();
		}
	} else {
		flash("error", "Missing file");
		ProjectController.statusMessage = "Error: Missing file";
	}
	return redirect(controllers.project.routes.ProjectController.showProject(name));
}
 
开发者ID:saikatgomes,项目名称:CS784-Data_Integration,代码行数:38,代码来源:RuleController.java

示例13: importRules

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
public static Result importRules(String name){
	DynamicForm form = form().bindFromRequest();
	Logger.info("PARAMETERS : " + form.data().toString());
	String table1Name = form.get("table1_name");
	String table2Name = form.get("table2_name");

	MultipartFormData body = request().body().asMultipartFormData();
	FilePart fp = body.getFile("csv_file_path");

	if (fp != null) {
		String fileName = fp.getFilename();
		String contentType = fp.getContentType();
		Logger.info("fileName: " + fileName + ", contentType: " + contentType);
		File file = fp.getFile();
		Project project = ProjectDao.open(name);

		try{
			List<Rule> rules = RuleDao.importRulesFromCSVWithHeader(project,
					table1Name, table2Name, file.getAbsolutePath());
			// save the features - this automatically updates and saves the project
			RuleDao.saveRules(name, rules);
			ProjectController.statusMessage = "Successfully imported " + rules.size() + " rules.";
		}
		catch(IOException ioe){
			flash("error", ioe.getMessage());
			ProjectController.statusMessage = "Error: " + ioe.getMessage();
		}
	} else {
		flash("error", "Missing file");
		ProjectController.statusMessage = "Error: Missing file";
	}
	return redirect(controllers.project.routes.ProjectController.showProject(name));
}
 
开发者ID:saikatgomes,项目名称:CS784-Data_Integration,代码行数:34,代码来源:RuleController.java

示例14: importMatchers

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
public static Result importMatchers(String name){
	DynamicForm form = form().bindFromRequest();
	Logger.info("PARAMETERS : " + form.data().toString());
	String table1Name = form.get("table1_name");
	String table2Name = form.get("table2_name");

	MultipartFormData body = request().body().asMultipartFormData();
	FilePart fp = body.getFile("csv_file_path");

	if (fp != null) {
		String fileName = fp.getFilename();
		String contentType = fp.getContentType();
		Logger.info("fileName: " + fileName + ", contentType: " + contentType);
		File file = fp.getFile();
		Project project = ProjectDao.open(name);

		try{
			List<Matcher> matchers = RuleDao.importMatchersFromCSVWithHeader(project,
					table1Name, table2Name, file.getAbsolutePath());
			// save the features - this automatically updates and saves the project
			RuleDao.saveMatchers(name, matchers);
			ProjectController.statusMessage = "Successfully imported " + matchers.size() + " matchers.";
		}
		catch(IOException ioe){
			flash("error", ioe.getMessage());
			ProjectController.statusMessage = "Error: " + ioe.getMessage();
		}
	} else {
		flash("error", "Missing file");
		ProjectController.statusMessage = "Error: Missing file";
	}
	return redirect(controllers.project.routes.ProjectController.showProject(name));
}
 
开发者ID:saikatgomes,项目名称:CS784-Data_Integration,代码行数:34,代码来源:RuleController.java

示例15: handleFileUploadForm

import play.mvc.Http.MultipartFormData; //导入方法依赖的package包/类
@BodyParser.Of (value = BodyParser.MultipartFormData.class, maxLength = 2 * 1024 * 1024)
public static Result handleFileUploadForm () {
	final MultipartFormData body = request ().body ().asMultipartFormData ();
	final FilePart uploadFile = body.getFile ("file");
	
	if (uploadFile == null) {
		return ok (uploadFileForm.render (null));
	}
	
	final String content = handleFileUpload (uploadFile.getFile ());
	
	return ok (uploadFileForm.render (content));
}
 
开发者ID:IDgis,项目名称:geo-publisher,代码行数:14,代码来源:Styles.java


注:本文中的play.mvc.Http.MultipartFormData.getFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。