RenameFile
The RenameFile
operation renames a file.
POST /wopi/files/(file_id)
If the host can't rename the file because the name requested is invalid or conflicts with an existing file, the host should try to generate a different name based on the requested name that meets the file name requirements.
If the host can't generate a different name, it should return an HTTP status code 400 Bad Request. The response must include an X-WOPI-InvalidFileNameError header that describes why the file name was invalid.
If the file is currently unlocked, the host should respond with a 200 OK and proceed with the rename.
If the file is currently locked and the X-WOPI-Lock value doesn't match the lock currently on the file the host must return a lock mismatch response (409 Conflict) and include an X-WOPI-Lock response header containing the value of the current lock on the file.
Tip
Office for the web includes contains UI that users can use to rename files. In order to activate this UI in Office for the web, you must implement the RenameFile operation, and also do the following:
- Set SupportsRename and UserCanRename to
true
in your CheckFileInfo response. - Set a FileNameMaxLength value if the default value isn't correct for your WOPI host.
Parameters
- file_id (string) – A string that specifies a file ID of a file managed by host. This string must be URL safe.
Query parameters
- access_token (string) – An access token that the host uses to determine whether the request is authorized.
Request headers
X-WOPI-Override – The string
RENAME_FILE
. This header is required.X-WOPI-Lock – A string provided by the WOPI client that the host uses to identify the lock on the file.
X-WOPI-RequestedName – A UTF-7 encoded string that's a file name, not including the file extension.
Response headers
X-WOPI-InvalidFileNameError – A string describing the reason the rename operation couldn't be completed. This header should only be included when the response code is 400 Bad Request. This value must only be used for logging purposes.
X-WOPI-Lock – A string value identifying the current lock on the file. This header must always be included when responding to the request with 409 Conflict. It shouldn't be included when responding to the request with 200 OK.
X-WOPI-LockFailureReason – An optional string value indicating the cause of a lock failure. This header might be included when responding to the request with 409 Conflict. There's no standard for how this string is formatted, and it must only be used for logging purposes.
X-WOPI-LockedByOtherInterface –
Deprecated: Deprecated since version 2015-12-15: This header is deprecated and should be ignored by WOPI clients.
Status Codes
200 OK – Success.
400 Bad Request – Specified name is illegal.
401 Unauthorized – Invalid access token.
404 Not Found – Resource not found or user unauthorized.
409 Conflict – Lock mismatch or locked by another interface. You must always include an X-WOPI-Lock response header containing the value of the current lock on the file when using this response code.
500 Internal Server Error – Server error.
501 Not Implemented – Operation not supported.
In addition to the request and response headers listed here, this operation might also use the Standard WOPI request and response headers. For more information, see Standard WOPI request and response headers.
Response
The response to a RenameFile
call is JSON containing a single required property:
Name (string) - The name of the renamed file without a path or file extension.
Important
The Name property returned can't include the file extension. This is different than other similar WOPI operations such as PutRelativeFile and CreateChildFile.