On Mar 25, 2009, at 11:15 AM, Anca Paula Luca wrote: > > I'm not at all knowledgeable of the REST API, but if it were a > method there to > attach a file and send back attached file name in JSON (or > something), it would > be so great. > You can do this, it's already supported by the REST API.
For example: curl -u Admin:admin -X PUT -H "Content-type: application/pdf" --data- binary @test.pdf http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome/attachments/test.pdf Will create an attachment on the Main.WebHome page and will return an XML containing all the information about the (newly created or updated) attachment. Something like: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <attachment xmlns="http://www.xwiki.org"> <link rel="http://www.xwiki.org/rel/page" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome "/> <link rel="http://www.xwiki.org/rel/attachmentData" href="http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome/attachments/test.pdf "/> <id>xwiki:[email protected]</id> <name>test.pdf</name> <size>32990</size> <version>1.3</version> <pageId>xwiki:Main.WebHome</pageId> <pageVersion>6.1</pageVersion> <mimeType>application/pdf</mimeType> <author>XWiki.Admin</author> <date>2009-03-25+01:00</date> <xwikiRelativeUrl>/xwiki/bin/download/Main/WebHome/test.pdf</ xwikiRelativeUrl> <xwikiAbsoluteUrl>http://localhost:8080/xwiki/bin/download/Main/WebHome/test.pdf </xwikiAbsoluteUrl> </attachment> If you want this information in JSON, just add an "Accept: application/ json" to the request and you are done: curl -u Admin:admin -X PUT -H "Content-type: application/pdf" -H "Accept: application/json" --data-binary @test.pdf http://localhost:8080/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome/attachments/test.pdf { "mimeType":"application/pdf", "pageVersion":"8.1", "xwikiRelativeUrl":"/xwiki/bin/download/Main/WebHome/test.pdf", "xwikiAbsoluteUrl":"http://localhost:8080/xwiki/bin/download/Main/WebHome/test.pdf ", "size":32990, "date":"java.util.GregorianCalendar[time=1237978840000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id=\"Europe/Paris\",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=184,lastRule=java.util.SimpleTimeZone[id=Europe/Paris,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2009,MONTH=2,WEEK_OF_YEAR=13,WEEK_OF_MONTH=4,DAY_OF_MONTH=25,DAY_OF_YEAR=84,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=0,HOUR_OF_DAY=12,MINUTE=0,SECOND=40,MILLISECOND=0,ZONE_OFFSET=3600000,DST_OFFSET=0]", "name":"test.pdf", "id":"xwiki:[email protected]", "author":"XWiki.Admin", "version":"1.4", "pageId":"xwiki:Main.WebHome" } Hope this helps. Cheers, Fabio _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

