私は rest-client-builder プラグイン ( http://grails.org/plugin/rest-client-builder ) を使用しており、ファイルを inputStream オブジェクトとして送信するという問題に直面しました。
プラグインのドキュメントから:
マルチパート リクエストは、リクエスト ボディのプロパティを File、URL、byte[]、または InputStream インスタンスに設定することで可能になります。
def resp = rest.post(url) {
contentType "multipart/form-data"
zip = new File(pluginPackage)
pom = new File(pomFile)
xml = new File(pluginXmlFile)
}
私のコード:
def post(String url, InputStream photo, String contentType, Cookie[] cookies = null) {
def rest = new RestBuilder()
def cookiesHeaderString = ""
if (cookies) {
cookiesHeaderString = WebUtils.buildCookiesHeader(cookies)
}
def resp = rest.post(url) {
header "Cookie", cookiesHeaderString
file = photo
contentType "multipart/form-data"
}
return resp?.responseEntity?.body
}
InputStream オブジェクトを送信する方法や、私が間違っていることを誰かが提案できますか?