Skip to content

Commit

Permalink
Merge pull request Sunbird-Knowlg#542 from krgauraw/release-3.6.0
Browse files Browse the repository at this point in the history
Issue #SB-23326 fix: fix for content upload api
  • Loading branch information
maheshkumargangula authored Feb 23, 2021
2 parents 50be938 + b711aec commit 94b71b2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class BaseController(protected val cc: ControllerComponents)(implicit e
JavaJsonUtils.deserialize[java.util.Map[String, Object]](body).getOrDefault("request", new java.util.HashMap()).asInstanceOf[java.util.Map[String, Object]]
}

def requestFormData()(implicit request: Request[AnyContent]) = {
def requestFormData(identifier: String)(implicit request: Request[AnyContent]) = {
val reqMap = new util.HashMap[String, AnyRef]()
if(!request.body.asMultipartFormData.isEmpty) {
val multipartData = request.body.asMultipartFormData.get
Expand All @@ -49,9 +49,9 @@ abstract class BaseController(protected val cc: ControllerComponents)(implicit e
}
}
if (null != multipartData.files && !multipartData.files.isEmpty) {
val file: File = new File("/tmp" + File.separator + request.body.asMultipartFormData.get.files.head.filename)
multipartData.files.head.ref.copyTo(file, false)
reqMap.put("file", file)
val file: File = new File("/tmp" + File.separator + identifier + "_" + System.currentTimeMillis + "_"+ request.body.asMultipartFormData.get.files.head.filename)
val copiedFile: File = multipartData.files.head.ref.copyTo(file, false).toFile
reqMap.put("file", copiedFile)
}
}
if(StringUtils.isNotBlank(reqMap.getOrDefault("fileUrl", "").asInstanceOf[String]) || null != reqMap.get("file").asInstanceOf[File]){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class ContentController @Inject()(@Named(ActorNames.CONTENT_ACTOR) contentActor:

def upload(identifier: String, fileFormat: Option[String], validation: Option[String]) = Action.async { implicit request =>
val headers = commonHeaders()
val content = requestFormData()
val content = requestFormData(identifier)
content.putAll(headers)
val contentRequest = getRequest(content, headers, "uploadContent")
setRequestContext(contentRequest, version, objectType, schemaName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AssetController @Inject()(@Named(ActorNames.CONTENT_ACTOR) contentActor:

def upload(identifier: String, fileFormat: Option[String], validation: Option[String]) = Action.async { implicit request =>
val headers = commonHeaders()
val content = requestFormData()
val content = requestFormData(identifier)
content.putAll(headers)
val contentRequest = getRequest(content, headers, "uploadContent")
setRequestContext(contentRequest, version, objectType, schemaName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ContentController @Inject()(@Named(ActorNames.CONTENT_ACTOR) contentActor:

def upload(identifier: String, fileFormat: Option[String], validation: Option[String]) = Action.async { implicit request =>
val headers = commonHeaders()
val content = requestFormData()
val content = requestFormData(identifier)
content.putAll(headers)
val contentRequest = getRequest(content, headers, "uploadContent")
setRequestContext(contentRequest, version, objectType, schemaName)
Expand Down

0 comments on commit 94b71b2

Please sign in to comment.