Play Scala Action not receiving Multipart Form Data

399
November 21, 2016, at 8:19 PM

I want to upload a file into my web server using Play Scala Framework. But the server is responding Bad Request (400). I have separate client hosted in different web server. I have made file upload action as minimul which is as follow:

  def upload() = Action.async(parse.multipartFormData) { request =>
    val body = request.body
    val optFile = body.files.headOption.map(_.ref.file)
    optFile match {
      case None => Future.successful(Ok("Missing Upload File").as("text/json"))
      case Some(file) => Future.successful(Ok("uploaded").as("text/json"))
    }
  }

The jQuery ajax request is set as follow:

var frm = new FormData() ;
frm.append('file', $('#uploadfiles')[0].files[0]);
    $.ajax( {
        url: 'http://localhost:9000/notes/upload',
  data: frm,
  processData: false,
        method: 'post',
        crossDomain: true,
  xhrFields: {
    withCredentials: true
  },
  contentType: 'multipart/form-data',
        success: function ( uploadStatus ) {
            alert('uploaded');
        },
        error: function ( error ) {
            alert('error');
        }
    } );

The update request is :

General
Remote Address:[::1]:9000
Request URL:http://localhost:9000/notes/upload
Request Method:POST
Status Code:400 Bad Request
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://localhost:3000
Content-Length:2148
Content-Type:text/html; charset=utf-8
Date:Mon, 28 Sep 2015 07:45:02 GMT
Vary:Origin
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:511
Content-Type:multipart/form-data
Cookie:connect.sid=s%3AWqi9VT3x3VctZ0_k1V0X5PWMJB0evrZG.8ux2doySJchVgqJC9tmt%2BOBMHCN%2FD1KBOXnfhGa%2BOfM
Host:localhost:9000
Origin:http://localhost:3000
Referer:http://localhost:3000/home
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36
Request Payload
------WebKitFormBoundaryhrfHwiE7FJD7GgSo
Content-Disposition: form-data; name="file"; filename="README"
Content-Type: application/octet-stream

------WebKitFormBoundaryhrfHwiE7FJD7GgSo--

Although, the request header is content type is multipart/form-data. My action is not letting upload files. Even body of action is not executed. Am I missing anything here or doing wrong? Any help will be of great appreciation. Thanks

Rent Charter Buses Company
READ ALSO
On changing enabled property of dropdownlist in asp.net CSS/jquery doesn't work.

On changing enabled property of dropdownlist in asp.net CSS/jquery doesn't work.

i have dropdownlist in web page having enabled property false.

312
CKeditor on focus ASP.NET

CKeditor on focus ASP.NET

I use ASP. NET with CKeditor (4.

343
Converting text of textarea in a text file while uploading through php

Converting text of textarea in a text file while uploading through php

I am using a textarea for input of text in my application of PHP and using data type Varchacr2 in oracle 10g to store the text of this textarea -.

339