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


Java BodyParser.MultipartFormData方法代码示例

本文整理汇总了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));
}
 
开发者ID:IDgis,项目名称:geo-publisher,代码行数:14,代码来源:Styles.java

示例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());
        }
    });
}
 
开发者ID:theAgileFactory,项目名称:maf-desktop-app,代码行数:52,代码来源:SharedStorageManagerController.java

示例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);
}
 
开发者ID:judgels-deprecated,项目名称:judgels-jophiel,代码行数:7,代码来源:UserProfileController.java


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