PutRelativeFile

Required for: Online
POST /wopi/files/(file_id)

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.

Important

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:

  1. Set the UserCanNotWriteRelative property to true always.
  2. Return a 501 Not Implemented to all PutRelativeFile requests.

Excel Online Note

Excel Online uses this operation in the following two ways:

  1. As part of the Save As feature. If PutRelativeFile is not supported, the Save As feature will not work in Excel Online.
  2. To support editing of some Excel files in Excel Online. Some files may contain content that is not currently supported in Excel Online. In this case, Excel Online 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 Online. If PutRelativeFile is not supported, files with unsupported content will not be editable in Excel Online.
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 will use to determine whether the request is authorized.
Request Headers:
 
  • X-WOPI-Override – The string PUT_RELATIVE. Required.
  • X-WOPI-SuggestedTarget

    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 501 Not Implemented.

  • X-WOPI-RelativeTarget

    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 true and 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 501 Not Implemented.

  • X-WOPI-OverwriteRelativeTarget

    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 false.

    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.
  • X-WOPI-FileConversion

    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.

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.
  • X-WOPI-LockedByOtherInterface

    Deprecated since version 2015-12-15: This header is deprecated and should be ignored by WOPI clients.

Status Codes:

See also

Standard WOPI request and response headers
In addition to the request/response headers listed here, this operation may also use the Standard WOPI request and response headers.

Response

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:

Type Default value
Boolean false
String The empty string
Integer/Long Varies; see individual properties for details
Array Empty array

Important

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:

Name
The string name of the file, including extension, without a path.
Url

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.

Danger

This property includes an access token and thus has important security implications. See Preventing ‘token trading’ for more details.

Optional response properties

HostViewUrl
The HostViewUrl, as a string, for the newly created file.
HostEditUrl
The HostEditUrl, as a string, for the newly created file.