- 浏览: 2560659 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Playframework and FileUpload in RESTful
File Upload in RESTful API right now, there are only 3 options till now.
1. Base64 encode the file, at the expense of increasing the data size by around 33%.
2. Send the file first in a multipart/form-data POST, and return and ID to the client. The client then sends the metadata with the ID. The server re-associates the file and the metadata.
3. Send the metadata first, and return an ID to the client. The client then sends the file with the ID, and the server re-associates the file and the metadata.
I may choose #2 or #3. Looking at play framework Uploading Files Chapter.
1. Playframework File Upload
I will use “multipart/form-data” encoding to make the form support mix standard form data with file attachment data.
Logging Level
ch.qos.logback.classic.Level TRACE, DEBUG, INFO, WARN and ERROR
https://www.playframework.com/documentation/2.4.3/SettingsLogger
https://www.playframework.com/documentation/2.4.3/ScalaLogging
def upload = Action(parse.multipartFormData) { request =>
request.body.file("file").map { file =>
import java.io.File
val filename = file.filename
val contentType = file.contentType
Ok("Resume there.")
}.getOrElse {
BadRequest(Json.obj("status" -> "OK", "message" -> "No files in the attachment."))
}
}
I was originally thinking that I may separate it into 2 steps. 1 - uploading file, 2 - parse file. But after think about this again. I may change that to 1 single step.
2. Directly Upload the File and Other Params
route configuration to upload the file content
# Resume Routes
POST /api/v1/resume/parseFile controllers.ResumeController.parseFile()
POST /api/v1/resume/parseContent controllers.ResumeController.parseContent()
The logging configuration
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/application.log</file>
<encoder>
<pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern>
</encoder>
</appender>
<appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="STDOUT" />
</appender>
<logger name="play" level="INFO" />
<logger name="application" level="DEBUG" />
<!-- Off these ones as they are annoying, and anyway we manage configuration ourself -->
<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
<logger name="controllers.ResumeController" level="DEBUG" />
<root level="WARN">
<appender-ref ref="ASYNCFILE" />
<appender-ref ref="ASYNCSTDOUT" />
</root>
</configuration>
Implementation Class to Deal with File
import java.io.FileInputStream
import com.wordnik.swagger.annotations._
import utils.IncludeLogger
import play.api.libs.json.{JsError, Json}
import play.api.mvc.{BodyParsers, Action, Controller}
…snip...
implicit val resumeWrites = Json.writes[Resume]
implicit val resumeReads = Json.reads[Resume]
@ApiOperation(value = "parseFile",
notes = "Parse the Resume File",
response = classOf[Resume],
httpMethod = "POST",
produces = "json",
position = 1)
@ApiImplicitParams(Array(
new ApiImplicitParam(
name="body",
value = "Resume File",
required = true,
dataType = "file",
paramType = "body")))
@ApiResponses(Array(new ApiResponse(code = 200, message = "Successful Parse Resume.", response = classOf[Resume]) ))
def parseFile = Action(parse.multipartFormData) { request =>
logger.debug("The request is here.")
val resume = request.body.files.map { file =>
val filename = file.filename
logger.debug("file: " + filename + " " + file.contentType)
val inputStream = new FileInputStream(file.ref.file)
ResumeUtil.parseInputStream(inputStream)
}
Ok(Json.toJson(resume))
}
Command to Play with Large Memory
>sbt clean update compile dist
>bin/classifier-play -Dconfig.file=conf/application.conf -Dhttp.port=8003 -Dhttp.address=0.0.0.0 -J-Xms1024M -J-Xmx8g -J-server
References:
http://stackoverflow.com/questions/3938569/how-do-i-upload-a-file-with-metadata-using-a-rest-web-service
http://stackoverflow.com/questions/4083702/posting-a-file-and-data-to-restful-webservice-as-json
File Upload for Scala
https://www.playframework.com/documentation/2.4.3/ScalaFileUpload
http://stackoverflow.com/questions/9452375/how-to-get-the-upload-file-with-other-inputs-in-play2
File Upload in RESTful API right now, there are only 3 options till now.
1. Base64 encode the file, at the expense of increasing the data size by around 33%.
2. Send the file first in a multipart/form-data POST, and return and ID to the client. The client then sends the metadata with the ID. The server re-associates the file and the metadata.
3. Send the metadata first, and return an ID to the client. The client then sends the file with the ID, and the server re-associates the file and the metadata.
I may choose #2 or #3. Looking at play framework Uploading Files Chapter.
1. Playframework File Upload
I will use “multipart/form-data” encoding to make the form support mix standard form data with file attachment data.
Logging Level
ch.qos.logback.classic.Level TRACE, DEBUG, INFO, WARN and ERROR
https://www.playframework.com/documentation/2.4.3/SettingsLogger
https://www.playframework.com/documentation/2.4.3/ScalaLogging
def upload = Action(parse.multipartFormData) { request =>
request.body.file("file").map { file =>
import java.io.File
val filename = file.filename
val contentType = file.contentType
Ok("Resume there.")
}.getOrElse {
BadRequest(Json.obj("status" -> "OK", "message" -> "No files in the attachment."))
}
}
I was originally thinking that I may separate it into 2 steps. 1 - uploading file, 2 - parse file. But after think about this again. I may change that to 1 single step.
2. Directly Upload the File and Other Params
route configuration to upload the file content
# Resume Routes
POST /api/v1/resume/parseFile controllers.ResumeController.parseFile()
POST /api/v1/resume/parseContent controllers.ResumeController.parseContent()
The logging configuration
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/application.log</file>
<encoder>
<pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern>
</encoder>
</appender>
<appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="FILE" />
</appender>
<appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="STDOUT" />
</appender>
<logger name="play" level="INFO" />
<logger name="application" level="DEBUG" />
<!-- Off these ones as they are annoying, and anyway we manage configuration ourself -->
<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
<logger name="controllers.ResumeController" level="DEBUG" />
<root level="WARN">
<appender-ref ref="ASYNCFILE" />
<appender-ref ref="ASYNCSTDOUT" />
</root>
</configuration>
Implementation Class to Deal with File
import java.io.FileInputStream
import com.wordnik.swagger.annotations._
import utils.IncludeLogger
import play.api.libs.json.{JsError, Json}
import play.api.mvc.{BodyParsers, Action, Controller}
…snip...
implicit val resumeWrites = Json.writes[Resume]
implicit val resumeReads = Json.reads[Resume]
@ApiOperation(value = "parseFile",
notes = "Parse the Resume File",
response = classOf[Resume],
httpMethod = "POST",
produces = "json",
position = 1)
@ApiImplicitParams(Array(
new ApiImplicitParam(
name="body",
value = "Resume File",
required = true,
dataType = "file",
paramType = "body")))
@ApiResponses(Array(new ApiResponse(code = 200, message = "Successful Parse Resume.", response = classOf[Resume]) ))
def parseFile = Action(parse.multipartFormData) { request =>
logger.debug("The request is here.")
val resume = request.body.files.map { file =>
val filename = file.filename
logger.debug("file: " + filename + " " + file.contentType)
val inputStream = new FileInputStream(file.ref.file)
ResumeUtil.parseInputStream(inputStream)
}
Ok(Json.toJson(resume))
}
Command to Play with Large Memory
>sbt clean update compile dist
>bin/classifier-play -Dconfig.file=conf/application.conf -Dhttp.port=8003 -Dhttp.address=0.0.0.0 -J-Xms1024M -J-Xmx8g -J-server
References:
http://stackoverflow.com/questions/3938569/how-do-i-upload-a-file-with-metadata-using-a-rest-web-service
http://stackoverflow.com/questions/4083702/posting-a-file-and-data-to-restful-webservice-as-json
File Upload for Scala
https://www.playframework.com/documentation/2.4.3/ScalaFileUpload
http://stackoverflow.com/questions/9452375/how-to-get-the-upload-file-with-other-inputs-in-play2
发表评论
-
Stop Update Here
2020-04-28 09:00 322I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 484NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 374Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 375Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 345Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 436Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 444Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 381Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 463VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 394Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 488NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 432Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 342Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 255GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 456GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 332GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 318Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 324Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 302Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 315Serverless with NodeJS and Tenc ...
相关推荐
【标题】"play-java-fileupload-example.zip_java_play_rately7" 涉及的主要知识点是使用Java和Play Framework处理文件上传。Play Framework是一个开源的Web应用框架,它以Scala和Java为开发语言,采用MVC(Model-...
* Integration with Apache FileUpload to support multi-part forms and easily handle large file uploads from browsers * Transformer filter to easily apply XSLT stylesheets on XML representations. It ...
o FILEUPLOAD-272: Performance Improvement in MultipartStream Details of all changes in 1.3.2 can be found in the changelog: http://commons.apache.org/proper/commons-fileupload/changes-report.html ...
开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2...
ASP.NET的FileUpload控件是Web开发中用于处理文件上传功能的重要组件。它允许用户从他们的本地计算机选择一个或多个文件,并将这些文件上传到服务器。在本文中,我们将深入探讨FileUpload控件的基本用法,包括如何在...
在.NET框架中,FileUpload控件是用于处理用户在Web应用程序中上传文件的关键组件。它允许用户选择本地计算机上的文件,并将其发送到服务器进行进一步处理。在这个特定的场景中,我们关注的是FileUpload控件的自动...
commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-...
在这个压缩包中,包含了`commons-fileupload-1.3.1-sources.jar`和`commons-fileupload-1.3.1.jar`两个文件,前者提供了源代码,后者是编译后的类库文件。 FileUpload组件的核心功能是解析HTTP请求中的多部分数据...
赠送jar包:commons-fileupload-1.4.jar; 赠送原API文档:commons-fileupload-1.4-javadoc.jar; 赠送源代码:commons-fileupload-1.4-sources.jar; 赠送Maven依赖信息文件:commons-fileupload-1.4.pom; 包含...
【FileUpload】是一个基于JSP技术的文件上传组件,它使用了特定的JAR包来实现文件上传功能。在Web应用中,文件上传是常见的需求,例如用户可能需要上传个人头像、文档或其他数据。FileUpload组件使得开发者能够轻松...
Apache Commons FileUpload库是一个强大的工具,专门设计用于处理这种需求。本篇将详细讲解使用FileUpload组件实现JSP文件上传所需的步骤和关键知识点。 首先,`fileUpload组件`是Apache Commons项目的一个子项目,...
赠送jar包:commons-fileupload-1.3.3.jar; 赠送原API文档:commons-fileupload-1.3.3-javadoc.jar; 赠送源代码:commons-fileupload-1.3.3-sources.jar; 赠送Maven依赖信息文件:commons-fileupload-1.3.3.pom;...
<jsp:useBean id="myUpload" scope="page" class="fileUpload.upBean" /> //初始化工作 myUpload.initialize(pageContext); //设定允许的文件后缀名 //myUpload.setAllowedExtList("gif,jpg"); //设定允许...
使用fileupload组件实现文件上传功能 FileUpload组件是Apache提供的一款文件上传组件,能够帮助我们轻松实现文件上传功能。下面我们将详细介绍使用FileUpload组件实现文件上传功能的步骤和要点: 首先,需要引入两...
《Apache Commons FileUpload组件详解》 Apache Commons FileUpload是一个用于处理HTTP请求中多部分数据的Java库,尤其在上传文件时极为有用。标题中的"commons-fileupload-1.4-bin.zip"表明这是一个包含Apache ...
标题“Java C++ and C# FileUpload”表明这个压缩包可能包含了关于在三种不同的编程语言——Java、C++和C#中实现文件上传功能的示例代码或工具。描述中的“博文链接:https://roger51.iteye.com/blog/123751”暗示...
commons commons-fileupload历史版本jar包集合,包括src源码 附件列表: commons-fileupload-1.0.zip commons-fileupload-1.1.1.zip commons-fileupload-1.1.zip commons-fileupload-1.2.1-bin.zip commons-...