-
- 2 minutes to read
-
Namespace: microsoft.graph
Use this API to retrieve the contents of an item in a specific format.
Not all files can be converted into all formats.
To download the item in its original format, see download an item's contents.
Prerequisites
To call this API, the user must have granted the application read access to the file the app wishes to convert.
HTTP request
GET /drive/items/{item-id}/content?format={format}
GET /drive/root:/{path and filename}:/content?format={format}
Query parameters
Parameter |
Type |
Description |
format |
string |
Specify the format the item's content should be downloaded as. |
The following values are valid for the format parameter:
Format value |
Description |
Supported source extensions |
pdf |
Converts the item into PDF format. |
csv, doc, docx, odp, ods, odt, pot, potm, potx, pps, ppsx, ppsxm, ppt, pptm, pptx, rtf, xls, xlsx |
Name |
Value |
Description |
if-none-match |
String |
If this request header is included and the eTag (or cTag) provided matches the current tag on the file, an HTTP 304 Not Modified response is returned. |
Example
GET /me/drive/items/{item-id}/content?format={format}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("format", "{format}")
};
var stream = await graphClient.Me.Drive.Items["{item-id}"].Content
.Request( queryOptions )
.GetAsync();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
const options = {
authProvider,
};
const client = Client.init(options);
let res = await client.api('/me/drive/items/{item-id}/content?format=%7Bformat%7D')
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/drive/items/{item-id}/content?format=%7Bformat%7D"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
MSGraphStream *stream = [[MSGraphStream alloc] initWithData:data error:&nserror];
}];
[meDataTask execute];
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new QueryOption("format", "{format}"));
InputStream stream = graphClient.customRequest("/me/drive/items/{item-id}/content", InputStream.class)
.buildRequest( requestOptions )
.get();
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Response
Returns a 302 Found
response redirecting to a pre-authenticated download URL for the converted file.
To download the converted file, your app must follow the Location
header in the response.
Pre-authenticated URLs are only valid for a short period of time (a few minutes) and do not require an Authorization
header to access.
HTTP/1.1 302 Found
Location: https://b0mpua-by3301.files.1drv.com/y23vmagahszhxzlcvhasdhasghasodfi
Error responses
See Error Responses for more information about how errors are returned.