本文整理汇总了Java中play.mvc.Http.MultipartFormData.FilePart类的典型用法代码示例。如果您正苦于以下问题:Java FilePart类的具体用法?Java FilePart怎么用?Java FilePart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FilePart类属于play.mvc.Http.MultipartFormData包,在下文中一共展示了FilePart类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: submit
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的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: saveAsAttachement
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的package包/类
/**
* Save the specified file as an attachment.
*
* @param fieldName
* the field name
* @param objectClass
* the object class
* @param objectId
* the object id
* @param attachmentPlugin
* the service which is managing attachments
*/
public static Long saveAsAttachement(String fieldName, Class<?> objectClass, Long objectId, IAttachmentManagerPlugin attachmentPlugin) throws IOException {
FileInputStream fIn = null;
try {
FileType fileType = getFileType(fieldName);
switch (fileType) {
case UPLOAD:
FilePart filePart = getFilePart(fieldName);
fIn = new FileInputStream(filePart.getFile());
return attachmentPlugin.addFileAttachment(fIn, filePart.getContentType(), getFileName(fieldName), objectClass, objectId);
case URL:
return attachmentPlugin.addUrlAttachment(getUrl(fieldName), getFileName(fieldName), objectClass, objectId);
default:
return null;
}
} catch (Exception e) {
String message = String.format("Failure while creating the attachments for : %s [class %s]", objectId, objectClass);
throw new IOException(message, e);
} finally {
IOUtils.closeQuietly(fIn);
}
}
开发者ID:theAgileFactory,项目名称:app-framework,代码行数:38,代码来源:FileAttachmentHelper.java
示例3: guardarArchivo
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的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
示例4: uploadExcel
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的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
示例5: uploadExcel
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的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
示例6: createNew
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的package包/类
private static Attachment createNew(FilePart file, String path) {
Attachment attachment = new Attachment();
attachment.setFileName(file.getFilename());
attachment.setFilePath(path);
attachment.setMimeType(file.getContentType());
attachment.save();
return attachment;
}
开发者ID:CSCfi,项目名称:exam,代码行数:9,代码来源:AttachmentController.java
示例7: addAttachmentToQuestion
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的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
示例8: addAttachmentToExam
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的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
示例9: submit
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的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
示例10: getFilePart
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的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
示例11: uploadFile
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的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.FilePart; //导入依赖的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.FilePart; //导入依赖的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.FilePart; //导入依赖的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.FilePart; //导入依赖的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
示例16: uploadFile
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的package包/类
public static Result uploadFile() {
MultipartFormData part = request().body().asMultipartFormData();
FilePart file = part.getFile("file");
String filename = file.getFilename();
String[] parts = filename.split(".");
String name = parts[0];
String ext;
try {
ext = parts[1];
}
catch (ArrayIndexOutOfBoundsException iobe) {
ext = "-";
}
User user = User.findByUsername(session().get("login"));
Document doc = new Document(file.getFile(), ext, user, name);
user.documentos.add(doc);
doc.save();
user.save();
return ok(profile.render(user));
}
开发者ID:Arquisoft,项目名称:ObservaTerra51,代码行数:29,代码来源:Application.java
示例17: upload
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的package包/类
public static Result upload() {
MultipartFormData body = request().body().asMultipartFormData();
FilePart picture = body.getFile("picture");
String extensaoPadraoDeImagens = Play.application().configuration().getString("extensaoPadraoDeImagens");
if (picture != null) {
String filmeId = form().bindFromRequest().get("filmeId");
String imagem = filmeId + extensaoPadraoDeImagens;
String contentType = picture.getContentType();
File file = picture.getFile();
String diretorioDeImagens = Play.application().configuration().getString("diretorioDeImagens");
String contentTypePadraoDeImagens = Play.application().configuration().getString("contentTypePadraoDeImagens");
if (contentType.equals(contentTypePadraoDeImagens)) {
file.renameTo(new File(diretorioDeImagens,imagem));
return ok(views.html.upload.render("Arquivo \"" + imagem + "\" do tipo [" + contentType + "] foi carregado com sucesso !"));
} else {
return ok(views.html.upload.render("Imagens apenas no formato \"" + contentTypePadraoDeImagens + "\" serão aceitas!"));
}
} else {
flash("error","Erro ao fazer upload");
return redirect(routes.Application.index());
}
}
开发者ID:boaglio,项目名称:play2-casadocodigo,代码行数:32,代码来源:FilmeCRUD.java
示例18: uploadImage
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的package包/类
/**
* Upload the specified image and return the link to it
*
* @return the image link in the system
*/
private static String uploadImage() {
String imageLocation = Play.application().configuration().getString("workshop.images.url") + File.separator;
String defaultImage = imageLocation + "default.png";
MultipartFormData body = request().body().asMultipartFormData();
FilePart picture = body != null ? body.getFile("image") : null;
if (picture != null) {
String fileName = picture.getFilename();
File file = picture.getFile();
// We save the file
String myUploadPath = Play.application().path()
+ File.separator
+ Play.application().configuration().getString("workshop.images.directory");
// We check if the dest file exists
File dest = new File(myUploadPath, fileName);
if ( dest.exists() ) {
dest.delete();
}
// If the file copy encounter an exception, we use the default picture
if ( FilesUtils.fastCopyFileCore( file, dest ) ) {
return imageLocation + fileName;
}
}
return defaultImage;
}
开发者ID:sqlilabs,项目名称:WorkshopManager,代码行数:35,代码来源:WorkshopController.java
示例19: uploadRessources
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的package包/类
/**
* Upload the specified File and return the link to it
*
* @return the File link in the system
*/
private static String uploadRessources( Workshop workshop ) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("[yyyy-MM]");
String destFolderName = simpleDateFormat.format( workshop.workshopSession.get(0).nextPlay ) + " - " + workshop.subject;
String ressourceLocation = Play.application().configuration().getString("workshop.ressources.url") + File.separator + destFolderName + File.separator;
MultipartFormData body = request().body().asMultipartFormData();
FilePart ressource = body != null ? body.getFile("workshopSupportFile") : null;
if (ressource != null && !StringUtils.EMPTY.equals( ressource.getFilename()) ) {
String fileName = ressource.getFilename();
File file = ressource.getFile();
// We save the file
String myUploadPath = Play.application().path() + File.separator
+ Play.application().configuration().getString("workshop.ressources.directory")
+ File.separator + destFolderName;
File destFolder = new File(myUploadPath);
destFolder.mkdirs();
// We check if the dest file exists
File dest = new File(myUploadPath, fileName);
if ( dest.exists() ) {
dest.delete();
}
// If the file copy encounter an exception, we use the default picture
if ( FilesUtils.fastCopyFileCore( file, dest ) ) {
return ressourceLocation + fileName;
}
}
return null;
}
开发者ID:sqlilabs,项目名称:WorkshopManager,代码行数:39,代码来源:WorkshopController.java
示例20: upload
import play.mvc.Http.MultipartFormData.FilePart; //导入依赖的package包/类
/**
* Upload a new file into the shared storage.
*
* @param isInput
* if true the field name containing the file uploaded is
* IFrameworkConstants.INPUT_FOLDER_NAME
* (IFrameworkConstants.OUTPUT_FOLDER_NAME otherwise)
* @return
*/
@BodyParser.Of(value = BodyParser.MultipartFormData.class, maxLength = MAX_FILE_SIZE)
public Promise<Result> upload(final boolean isInput) {
final String folderName = isInput ? IFrameworkConstants.INPUT_FOLDER_NAME : IFrameworkConstants.OUTPUT_FOLDER_NAME;
final
// Test if the max number of files is not exceeded
String[] files;
try {
files = getSharedStorageService().getFileList("/" + folderName);
} catch (IOException e1) {
return redirectToIndexAsPromiseWithErrorMessage(null);
}
int numberOfFiles = files != null ? files.length : 0;
if (numberOfFiles >= getConfiguration().getInt("maf.sftp.store.maxfilenumber")) {
return redirectToIndexAsPromiseWithErrorMessage(Msg.get("admin.shared_storage.upload.error.max_number"));
}
// Perform the upload
return Promise.promise(new Function0<Result>() {
@Override
public Result apply() throws Throwable {
try {
MultipartFormData body = request().body().asMultipartFormData();
FilePart filePart = body.getFile(folderName);
if (filePart != null) {
IOUtils.copy(new FileInputStream(filePart.getFile()),
getSharedStorageService().writeFile("/" + folderName + "/" + filePart.getFilename(), true));
Utilities.sendSuccessFlashMessage(Msg.get("form.input.file_field.success"));
} else {
Utilities.sendErrorFlashMessage(Msg.get("form.input.file_field.no_file"));
}
} catch (Exception e) {
Utilities
.sendErrorFlashMessage(Msg.get("admin.shared_storage.upload.file.size.invalid", FileUtils.byteCountToDisplaySize(MAX_FILE_SIZE)));
String message = String.format("Failure while uploading a new file in %s", folderName);
log.error(message);
throw new IOException(message, e);
}
return redirect(routes.SharedStorageManagerController.index());
}
});
}
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:52,代码来源:SharedStorageManagerController.java
注:本文中的play.mvc.Http.MultipartFormData.FilePart类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论