HTTP请求PUT文件(图像)到Swift RESTful API(Grails)

时间:2015-08-13 10:55:37

标签: swift api rest grails httprequest

// authenticate
def authSite = new HTTPBuilder( 'https://*********.objectstore.eu/' )
authSite.auth.basic '******', '******'

def filestore = new File("C:/*****")
filestore.createNewFile()
FileUtils.writeStringToFile(filestore, "datawhathwat")

//save object
authSite.request(PUT) { req ->
    uri.path = '/images/********.txt' 
    headers.'Content-Type' = 'image/jpg'

    body: "filestore"
}

authSite.shutdown()

使用此代码时,标题会通过,创建一个文件,但文件为空。

以下是API文档的链接:http://developer.openstack.org/api-ref-objectstorage-v1.html#createOrReplaceObject

1 个答案:

答案 0 :(得分:0)

在请求正文中,您传递的是字符串,而不是您尝试上传的文件的内容。以这种方式将文件的内容放入正文:

contact_
相关问题