Created
July 3, 2014 15:22
-
-
Save nawada/1a9c61350e23119020d2 to your computer and use it in GitHub Desktop.
PlayFramework2.2.1で、jQuery使ってファイルアップロード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Result upload() { | |
MultipartFormData file = request().body().asMultipartFormData(); | |
String extraData = file.asFormUrlEncoded().get("ExtraData")[0]; // => hogehoge | |
ObjectNode jsonData = Json.newObject(); | |
jsonData.put("status", "OK"); | |
return ok(jsonData); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /file/to/upload controller.Application.upload() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="file" id="file"> | |
<a href="#" id="send"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#send").click(function() { | |
var data = new FormData($("#file")); | |
data.append("ExtraData", "hogehoge"); | |
$.ajax({ | |
url: "/file/to/upload", | |
type: "POST", | |
data: data, | |
processData: false, | |
contentType: false, | |
success: function(result) { | |
alert(result.status); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment