> ## Documentation Index
> Fetch the complete documentation index at: https://developer.box.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Download File

export const MultiRelatedLinks = ({sections = []}) => {
  if (!sections || sections.length === 0) {
    return null;
  }
  return <div className="space-y-8">
      {sections.map((section, index) => <RelatedLinks key={index} title={section.title} items={section.items} />)}
    </div>;
};

export const RelatedLinks = ({title, items = []}) => {
  const getBadgeClass = badge => {
    if (!badge) return "badge-default";
    const badgeType = badge.toLowerCase().replace(/\s+/g, "-");
    return `badge-${badge === "ガイド" ? "guide" : badgeType}`;
  };
  if (!items || items.length === 0) {
    return null;
  }
  return <div className="my-8">
      {}
      <h3 className="text-sm font-bold uppercase tracking-wider mb-4">{title}</h3>

      {}
      <div className="flex flex-col gap-3">
        {items.map((item, index) => <a key={index} href={item.href} className="py-2 px-3 rounded related_link hover:bg-[#f2f2f2] dark:hover:bg-[#111827] flex items-center gap-3 group no-underline hover:no-underline border-b-0">
            {}
            <span className={`px-2 py-1 rounded-full text-xs font-semibold uppercase tracking-wide flex-shrink-0 ${getBadgeClass(item.badge)}`}>
              {item.badge}
            </span>

            {}
            <span className="text-base">{item.label}</span>
          </a>)}
      </div>
    </div>;
};

export const Link = ({href, children, className, ...props}) => {
  const localizedHref = localizeLink(href);
  return <a href={localizedHref} className={className} {...props}>
      {children}
    </a>;
};

To download a file, pass the <Link href="/reference/get-files-id-content">`GET /files/:id/content`</Link> the ID of the file
to get the content for.

<CodeGroup>
  ```sh cURL theme={null}
  curl -i -L -X GET "https://api.box.com/2.0/files/12345/content" \
       -H "authorization: Bearer <ACCESS_TOKEN>" 
  ```

  ```typescript Node/TypeScript v10 theme={null}
  const fs = require('fs');

  const fileContent = await client.downloads.downloadFile('123456789');
  const fileWriteStream = fs.createWriteStream('file.pdf');
  fileContent.pipe(fileWriteStream);
  ```

  ```python Python v10 theme={null}
  client.downloads.download_file(uploaded_file.id)
  ```

  ```cs .NET v10 theme={null}
  await client.Downloads.DownloadFileAsync(fileId: uploadedFile.Id);
  ```

  ```swift Swift v10 theme={null}
  let downloadsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
  let destinationURL = downloadsDirectoryURL.appendingPathComponent("file.txt")

  let url = try await client.downloads.downloadFile(fileId: file.id, downloadDestinationURL: destinationURL)

  if let fileContent = try? String(contentsOf: url, encoding: .utf8) {
      print("The content of the file: \(fileContent)")
  }
  ```

  ```java Java v10 theme={null}
  client.getDownloads().downloadFile(uploadedFile.getId())
  ```

  ```java Java v5 theme={null}
  BoxFile file = new BoxFile(api, "id");
  BoxFile.Info info = file.getInfo();

  FileOutputStream stream = new FileOutputStream(info.getName());
  file.download(stream);
  stream.close();
  ```

  ```python Python v4 theme={null}
  file_id = '11111'
  file_content = client.file(file_id).content()
  ```

  ```cs .NET v6 theme={null}
  Stream fileContents = await client.FilesManager.DownloadStreamAsync(id: "11111");
  ```

  ```javascript Node v4 theme={null}
  var fs = require('fs');
  client.files.getReadStream('12345', null, function(error, stream) {

  	if (error) {
  		// handle error
  	}

  	// write the file to disk
  	var output = fs.createWriteStream('/path/to/file');
  	stream.pipe(output);
  });
  ```
</CodeGroup>

## Download URL

When not using the SDKs, this API call will return a `HTTP 302 Found` status
code, with a `location` header containing a link to the download URL, which
looks something like this.

```sh theme={null}
https://dl.boxcloud.com/d/1/[long-random-string]/download
```

By using the `-L` flag in cURL we are able to automatically follow this
redirect.

<Info>
  In our SDKs this will result in the binary data to be downloaded. In the API
  this will result in a download URL being returned via the `location` header.

  It is possible to <Link href="/guides/downloads/get-url">get the download URL</Link> via the SDKs as well.
</Info>

## Download URL expiry

Although this download URL can be passed to a user's browser to allow them to
download the file, the URL does expire and should be requested again for any
further downloads.

## File not ready

If the file is not ready to be downloaded yet a `retry-after` header will be
returned indicating the time in seconds after which the file will be available
for the client to download.

This response can occur when the file was uploaded immediately before the
download request.

<RelatedLinks
  title="RELATED APIS"
  items={[
{ label: translate("Download file"), href: "/reference/get-files-id-content", badge: "GET" }
]}
/>

<RelatedLinks
  title="RELATED GUIDES"
  items={[
{ label: translate("Upload New File"), href: "/guides/uploads/direct/file", badge: "GUIDE" }
]}
/>
