files/{fileid}/properties (PUT)
Overview
Perform changes on multiple attachment properties
- REST Method: PUT
- Method Access: public
Uri Parameters
Name | Type | Description |
fileid | int | identifies a file by ID |
Query Parameters
Name | Type | Description |
authenticate | bool? | Force authentication for request (default: false) |
redirects | int? | If zero, do not follow page redirects. |
Return Codes
Name | Value | Description |
OK | 200 | The request completed successfully |
Bad Request | 400 | Invalid input parameter or request body |
Forbidden | 403 | UPDATE access is required |
Not Found | 404 | Requested file could not be found |
Message Format
Input is a list of property xml blocks. Only text values are allowed to be modified via this feature. To modify a non-text property value, use PUT: files/{fileid}/properties/{key} instead. Properties are deleted if no contents node is provided. An etag is not required for deleting properties.
<properties> <property name="{text}" etag="{text}"> <contents type="{text}">{text}</contents> <change-description>{text}</change-description> </property> <property name="{text}"/> </properties>
Response is a list of the standard property xml blocks as well as any error blocks.
<properties count="{int}" href="{uri}"> <property name="{text}" href="{uri}" etag="{text}"> <contents type="{text}" href="{uri}">{text}</contents> <date.modified>{date}</date.modified> <user.modified id="{int}" href="{uri}"> <nick>{text}</nick> <username>{text}</username> </user.modified> <change-description>{text}</change-description> </property> <property name="{text}"> <status code="{int}"> <error> <status>{int}</status> <title>{text}</title> <message>{text}</message> <uri>{uri}</uri> </error> </status> </property> </properties>
Implementation Notes
- The response XML will contain the contents text only for text based mimetypes with values less than 2048 chars in length. Otherwise the contents is available at the URI pointed to by property/contents/@href.
C# Sample: Modify File Properties
Authentication is performed and a file property is created named "myprop". Using the batch property update feature, "myprop" is updated with a new value with the current value's etag. A non existent property "propertyToDelete" is attempted to be deleted by not specifying a new content value.
Sample Code
Plug p = Plug.New("http://devwiki/@api/deki"); p.At("users", "authenticate").WithCredentials("sysop", "password").Get(); XDoc myPropResponse = p.At("files", "42", "properties") .WithHeader("Slug", "myprop") .Post(DreamMessage.Ok(MimeType.TEXT_UTF8, "initial value")).AsDocument(); XDoc body = new XDoc("properties"); body.Start("property").Attr("name", "myprop").Attr("etag", myPropResponse["/property/@etag"].AsText) .Start("contents").Attr("type", "text/plain").Value("new value for property").End() .Elem("description", "description of change") .End(); body.Start("property").Attr("name", "propertyToDelete").End(); XDoc response = p.At("files", "42", "properties") .Put(body).AsDocument();
Sample Response from executing Code
<properties count="1" href="http://devwiki/@api/deki/files/42/properties"> <property name="myprop" href="http://devwiki/@api/deki/files/42/properties/myprop/info" etag="4465.r2_ts2009-03-20T23:52:50Z"> <contents type="text/plain" href="http://devwiki/@api/deki/files/42/properties/myprop">new value for property</contents> <date.modified>2009-03-20T23:52:50Z</date.modified> <user.modified id="1" href="http://devwiki/@api/deki/users/1"> <nick>Sysop</nick> <username>Sysop</username> </user.modified> <change-description>description of change</change-description> <status code="200" /> </property> <property name="propertyToDelete"> <status code="400"> <error> <status>400</status> <title>Bad Request</title> <message>The property 'propertyToDelete' does not exist and cannot be deleted.</message> <uri>http://devwiki/@api/deki/files/42/properties</uri> </error> </status> </property> </properties>
Implementation notes
Add notes about requirements or config values
Curl Sample: Modify File Properties
The following command applies the properties listed in "properties.xml" to a file with file ID = 1.
Sample Code
curl -u username:password -H "Content-Type: application/xml" -T properties.xml -i http://mindtouch.address/@api/deki/files/1/properties
Implementation notes
curl flags
- -u
- Basic HTTP authentication. Sends a username and password to server so it can verify whether a user is of privilege to perform specific operation.
- -H
- Adds a header or modifies an existing one. In this case, since an xml document is being sent, the content type must be set to "application/xml". The server will not accept the request otherwise.
- -T file
- Specifies the .xml file that contains the user property data.
- -i
- Includes the HTTP response header in the output. Useful for debugging.
Example
We want to make some changes to a file's (file ID = 9) properties. The following XML document adds a couple properties and removes the "iscopyright" property added in this example.
fileprop.xml
Content-Type: application/xml
<properties> <!-- Add a couple properties --> <property name="blackandwhite"> <contents type="text/plain">yes</contents> </property> <property name="type"> <contents type="text/plain">image</contents> </property> <!-- Remove a property, to do this omit contents element --> <property name="iscopyright"/> </properties>
Command Line
curl -u admin:password -H "Content-Type: application/xml" -T fileprop.xml -i http://192.168.168.110/@api/deki/files/9/properties
HTTP Response Headers
HTTP/1.1 200 OK Date: Fri, 15 Jan 2010 01:50:28 GMT Server: Dream-HTTPAPI/1.7.2.17433 X-Deki-Site: id="default" Content-Type: application/xml; charset=utf-8 Content-Length: 2421 Via: 1.1 dekiwiki
HTTP Response Body
Content-Type: application/xml
<?xml version="1.0"?> <properties count="3" href="http://192.168.168.110/@api/deki/files/9/properties"> <property name="blackandwhite" href="http://192.168.168.110/@api/deki/files/9/properties/blackandwhite/info" etag="48.r1_ts2010-01-15T01:50:28Z"> <contents type="text/plain" size="3" href="http://192.168.168.110/@api/deki/files/9/properties/blackandwhite">yes</contents> <date.modified>2010-01-15T01:50:28Z</date.modified> <user.modified id="1" href="http://192.168.168.110/@api/deki/users/1"> <nick>Admin</nick> <username>Admin</username> <email>melder@mindtouch.com</email> <hash.email>637b79dca5c8ebdc4347bccca42d3487</hash.email> <uri.gravatar>http://www.gravatar.com/avatar/637b79dca5c8ebdc4347bccca42d3487</uri.gravatar> </user.modified> <status code="200"/> </property> <property name="type" href="http://192.168.168.110/@api/deki/files/9/properties/type/info" etag="49.r1_ts2010-01-15T01:50:28Z"> <contents type="text/plain" size="5" href="http://192.168.168.110/@api/deki/files/9/properties/type">image</contents> <date.modified>2010-01-15T01:50:28Z</date.modified> <user.modified id="1" href="http://192.168.168.110/@api/deki/users/1"> <nick>Admin</nick> <username>Admin</username> <email>melder@mindtouch.com</email> <hash.email>637b79dca5c8ebdc4347bccca42d3487</hash.email> <uri.gravatar>http://www.gravatar.com/avatar/637b79dca5c8ebdc4347bccca42d3487</uri.gravatar> </user.modified> <status code="200"/> </property> <property name="iscopyright" href="http://192.168.168.110/@api/deki/files/9/properties/iscopyright/info" etag="47.r2_ts2010-01-15T01:50:28Z"> <contents type="text/plain" size="2" href="http://192.168.168.110/@api/deki/files/9/properties/iscopyright">no</contents> <date.modified>2010-01-15T01:50:28Z</date.modified> <user.modified id="1" href="http://192.168.168.110/@api/deki/users/1"> <nick>Admin</nick> <username>Admin</username> <email>melder@mindtouch.com</email> <hash.email>637b79dca5c8ebdc4347bccca42d3487</hash.email> <uri.gravatar>http://www.gravatar.com/avatar/637b79dca5c8ebdc4347bccca42d3487</uri.gravatar> </user.modified> <user.deleted id="1" href="http://192.168.168.110/@api/deki/users/1"> <nick>Admin</nick> <username>Admin</username> <email>melder@mindtouch.com</email> <hash.email>637b79dca5c8ebdc4347bccca42d3487</hash.email> <uri.gravatar>http://www.gravatar.com/avatar/637b79dca5c8ebdc4347bccca42d3487</uri.gravatar> </user.deleted> <date.deleted>2010-01-15T01:50:28Z</date.deleted> <status code="200"/> </property> </properties>
Notes
- To view all properties attached to a specific file, fetch its raw XML data. In this case, the path is <http://192.168.168.110/@api/deki/files/9/properties>.