本文整理汇总了Java中play.mvc.BodyParser.MultipartFormData方法的典型用法代码示例。如果您正苦于以下问题:Java BodyParser.MultipartFormData方法的具体用法?Java BodyParser.MultipartFormData怎么用?Java BodyParser.MultipartFormData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.mvc.BodyParser
的用法示例。
在下文中一共展示了BodyParser.MultipartFormData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleFileUploadForm
import play.mvc.BodyParser; //导入方法依赖的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));
}
示例2: upload
import play.mvc.BodyParser; //导入方法依赖的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());
}
});
}
示例3: postAvatar
import play.mvc.BodyParser; //导入方法依赖的package包/类
@BodyParser.Of(value = BodyParser.MultipartFormData.class, maxLength = (2 << 20))
@Authenticated(value = {LoggedIn.class, HasRole.class})
@Transactional
public Result postAvatar() {
return postServiceAvatar(null);
}