Skip to content

Commit

Permalink
Support setting of content type when the linkis HTTP client uploads f…
Browse files Browse the repository at this point in the history
…iles

close #906
  • Loading branch information
peacewong committed Jul 16, 2021
1 parent 790cd89 commit 84317a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object Utils extends Logging {
System.exit(-1)
throw e
case er: Error =>
error("Throw error", er.getCause)
error("Throw error", er)
throw er
case t => catchOp(t)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ abstract class AbstractHttpClient(clientConfig: ClientConfig, clientName: String
upload.inputStreams.foreach { case (k, v) =>
builder.addBinaryBody(k, v, ContentType.create("multipart/form-data"), k)
}
upload.binaryBodies.foreach(binaryBody => builder.addBinaryBody(binaryBody.parameterName, binaryBody.inputStream, binaryBody.contentType, binaryBody.fileName))
upload match {
case get: GetAction => get.getParameters.
retain((k, v) => v != null && k != null).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package com.webank.wedatasphere.linkis.httpclient.request

import java.util

import org.apache.http.entity.ContentType

import scala.tools.nsc.interpreter.InputStream


Expand All @@ -27,7 +29,7 @@ trait UploadAction extends UserAction {
* 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]
@Deprecated val files: util.Map[String, String]
/**
* The inputStream that needs to be uploaded, the key is the parameter name, and the value is the input stream.
* 需要上传的输入流,key为参数名,value为输入流
Expand All @@ -37,7 +39,20 @@ trait UploadAction extends UserAction {
* 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]()
@Deprecated def inputStreamNames: util.Map[String, String] = new util.HashMap[String, String]()
def binaryBodies: util.List[BinaryBody] = new util.ArrayList[BinaryBody](0)
def user: Option[String] = Option(getUser)

}

case class BinaryBody(parameterName: String, inputStream: InputStream, fileName: String, contentType: ContentType)
object BinaryBody {
def apply(parameterName: String, inputStream: InputStream, fileName: String, contentType: String): BinaryBody =
new BinaryBody(parameterName, inputStream, fileName, ContentType.create(contentType))

def apply(parameterName: String, inputStream: InputStream): BinaryBody =
new BinaryBody(parameterName, inputStream, null, ContentType.DEFAULT_BINARY)

def apply(parameterName: String, inputStream: InputStream, fileName: String): BinaryBody =
new BinaryBody(parameterName, inputStream, fileName, ContentType.DEFAULT_BINARY)
}

0 comments on commit 84317a0

Please sign in to comment.