- Required for
The PutRelativeFile operation creates a new file on the host based on the current file. The host must use the content in the POST body to create a new file.
The PutRelativeFile operation has two distinct modes: specific and suggested. The primary difference between the two modes is whether the WOPI client expects the host to use the file name provided exactly (specific mode) or if the host can adjust the file name in order to make the request succeed (suggested mode).
Hosts can determine the mode of the operation based on which of the mutually exclusive X-WOPI-RelativeTarget (indicates specific mode) or X-WOPI-SuggestedTarget (indicates suggested mode) request headers is used. The expected behavior for each mode is described in detail below.
The PutRelativeFile operation may be called on a file that is not locked, so the X-WOPI-Lock request header is not included in this operation. An example of when this might occur is if a user uses the Save As feature when viewing a document in read-only mode. The source file will not be locked in this case, but the PutRelativeFile operation will be invoked on it.
Note, however, that a file matching the target name might be locked, and in specific mode, the host must respond with a 409 Conflict and include a X-WOPI-Lock response header as described below.
If a WOPI host sets the SupportsUpdate property in CheckFileInfo to
true, then the host is expected to implement the PutRelativeFile operation. However, a host may choose not to implement this operation even though SupportsUpdate is
true, but they must do the following:
Excel for the web Note
Excel for the web uses this operation in the following two ways:
As part of the Save As feature. If PutRelativeFile is not supported, the Save As feature will not work in Excel for the web.
To support editing of some Excel files in Excel for the web. Some files may contain content that is not currently supported in Excel for the web. In this case, Excel for the web will prompt the user to save an editable copy of the document, removing all unsupported content so that the file can be edited in Excel for the web. If PutRelativeFile is not supported, files with unsupported content will not be editable in Excel Online.
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 will use to determine whether the request is authorized.
- Request Headers
X-WOPI-Override – The string
A UTF-7 encoded string specifying either a file extension or a full file name, including the file extension. Hosts can differentiate between full file names and extensions as follows:
If the string begins with a period (
.), it is a file extension.
Otherwise, it is a full file name.
If only the extension is provided, the name of the initial file without extension should be combined with the extension to create the proposed name.
The response to a request including this header must never result in a 400 Bad Request or 409 Conflict. Rather, the host must modify the proposed name as needed to create a new file that is both legally named and does not overwrite any existing file, while preserving the file extension.
This header must be present if X-WOPI-RelativeTarget is not present; the two headers are mutually exclusive. If both headers are present the host should respond with a 400 Bad Request or 501 Not Implemented.
A UTF-7 encoded string that specifies a full file name including the file extension. The host must not modify the name to fulfill the request.
If the specified name is illegal, the host must respond with a 400 Bad Request.
If a file with the specified name already exists, the host must respond with a 409 Conflict, unless the X-WOPI-OverwriteRelativeTarget request header is set to
true. When responding with a 409 Conflict for this reason, the host may include an X-WOPI-ValidRelativeTarget specifying a file name that is valid.
If the X-WOPI-OverwriteRelativeTarget request header is set to
trueand a file with the specified name already exists and is locked, the host must respond with a 409 Conflict and include an X-WOPI-Lock response header containing the value of the current lock on the file.
This header must be present if X-WOPI-SuggestedTarget is not present; the two headers are mutually exclusive. If both headers are present the host should respond with a 400 Bad Request or 501 Not Implemented.
A Boolean value that specifies whether the host must overwrite the file name if it exists. The default value is
false. In other words, if X-WOPI-OverwriteRelativeTarget is not explicitly included on the request, hosts must behave as though its value is
This header is only valid if the X-WOPI-RelativeTarget is also included on the request. It must be ignored in all other cases.
If the user is not authorized to overwrite the target file, the host must respond with a 501 Not Implemented.
X-WOPI-Size – An integer that specifies the size of the file in bytes.
A header whose presence indicates that the request is being made in the context of a binary document conversion. This header will only be included on the request in that case. Thus, if X-WOPI-FileConversion is not explicitly included on the request, hosts must behave as if the PutRelativeFile request is not being made as part of a binary document conversion.
See Editing binary document formats for more information on the conversion process and how this header can be used.
- Request Body
The request body must be the full binary contents of the file.
- Response Headers
X-WOPI-ValidRelativeTarget – A UTF-7 encoded string that specifies a full file name including the file extension. This header may be used when responding with a 409 Conflict because a file with the requested name already exists, or when responding with a 400 Bad Request because the requested name contained invalid characters. If this response header is included, the WOPI client should automatically retry the PutRelativeFile operation using the contents of this header as the X-WOPI-RelativeTarget value and should not display an error message to the user.
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 should not 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 may be included when responding to the request with 409 Conflict. There is no standard for how this string is formatted, and it must only be used for logging purposes.
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
404 Not Found – Resource not found/user unauthorized
409 Conflict – Target file already exists or the file is locked; if the target file is locked, an X-WOPI-Lock response header containing the value of the current lock on the file must always be included
413 Request Entity Too Large – File is too large; the maximum size is host-specific
500 Internal Server Error – Server error
501 Not Implemented – Operation not supported; if the host sets the SupportsUpdate and UserCanNotWriteRelative properties to
truein CheckFileInfo, this response code must be used when this operation is called
The response to a PutRelativeFile call is JSON (as specified in RFC 4627) containing a number of properties, some of which are optional.
All optional values default to the following values based on their type:
The empty string
Varies; see individual properties for details
No properties should be set to
null. If you do not wish to set a property, simply omit it from
the response and WOPI clients will use the default value.
Required response properties¶
The following properties must be present in all PutRelativeFile responses:
The string name of the file, including extension, without a path.
A string URI of the form
http://server/<...>/wopi/files/(file_id)?access_token=(access token), of the newly created file on the host. This URL is the WOPISrc for the new file with an access token appended. Or, stated differently, it is the URL to the host’s Files endpoint for the new file, along with an access token. A GET request to this URL will invoke the CheckFileInfo operation.