Skip to content

Commit

Permalink
UploadAction support to upload a inputStream with a file name in modu…
Browse files Browse the repository at this point in the history
…le core/httpclient.

closes #72
  • Loading branch information
wushengyeyouya committed Oct 10, 2019
1 parent 238440c commit afc07b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
* limitations under the License.
*/

/*
* Created by ${USER} on ${DATE}.
*/

package com.webank.wedatasphere.linkis.httpclient

import java.io.{File, InputStream}
Expand Down Expand Up @@ -138,7 +134,7 @@ abstract class AbstractHttpClient(clientConfig: ClientConfig, clientName: String
}
var request = requestAction match {
case upload: UploadAction =>
req.setContentType("multipart/form-data", Configuration.BDP_ENCODING.getValue).POST
req = req.setContentType("multipart/form-data", Configuration.BDP_ENCODING.getValue).POST
if(upload.files != null && upload.files.nonEmpty) {
val fs = upload.user.map(getFsByUser(_, new FsPath(upload.files.head._2)))
upload.files.foreach { case (k, v) =>
Expand All @@ -157,7 +153,7 @@ abstract class AbstractHttpClient(clientConfig: ClientConfig, clientName: String
val filePart = new FilePart(k, new PartSource{
val length = v.available
override def getLength: Long = length
override def getFileName: String = k
override def getFileName: String = upload.inputStreamNames.getOrDefault(k, k)
override def createInputStream(): InputStream = v
})
req = req.addBodyPart(filePart)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
* limitations under the License.
*/

/*
* Created by ${USER} on ${DATE}.
*/

package com.webank.wedatasphere.linkis.httpclient.request

import scala.tools.nsc.interpreter.InputStream
Expand All @@ -30,15 +26,20 @@ import java.util
trait UploadAction extends UserAction {

/**
* The file to be uploaded, the key is the file name, and the value is the file path.
* 需要上传的文件,key为文件名,value为文件路径
* The file to be uploaded, the key is the parameter name, and the value is the file path.
* 需要上传的文件,key为参数名,value为文件路径
*/
val files: util.Map[String, String]
/**
* The input stream that needs to be uploaded, the key is the file name, and the value is the input stream.
* 需要上传的输入流,key为文件名,value为输入流
* The inputStream that needs to be uploaded, the key is the parameter name, and the value is the input stream.
* 需要上传的输入流,key为参数名,value为输入流
*/
def inputStreams: util.Map[String, InputStream] = new util.HashMap[String, InputStream]()
/**
* The inputStream that needs to be uploaded, the key is the parameter name, and the value is the fileName of inputStream.
* 需要上传的输入流,key为参数名,value为输入流的文件名
*/
def inputStreamNames: util.Map[String, String] = new util.HashMap[String, String]()
def user: Option[String] = Option(getUser)

}

0 comments on commit afc07b1

Please sign in to comment.