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

# Upload New 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>;
};

<RelatedLinks
  title="REQUIRED GUIDES"
  items={[
{ label: translate("Preflight Check"), href: "/guides/uploads/check", badge: "GUIDE" }
]}
/>

To upload a file to Box via direct upload, make an API call to the
<Link href="/reference/post-files-content">`POST /files/content`</Link> API with the content of the file, the desired
file name, and the folder ID.

<Tip>
  To upload files to the Archive folder, you need to first enable the <Link href="/guides/api-calls/permissions-and-errors/scopes">Global
  Content Manager</Link> (GCM) scope in the Developer Console.
</Tip>

<CodeGroup>
  ```sh cURL theme={null}
  curl -i -X POST "https://upload.box.com/api/2.0/files/content" \
       -H "authorization: Bearer <ACCESS_TOKEN>" \
       -H "content-type: multipart/form-data" \
       -F attributes='{"name":"Contract.pdf", "parent":{"id":"11446498"}}' \
       -F file=@<FILE_NAME>
  ```

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

  const attrs = { name: 'filename.txt', parent: { id: '0' } };
  const body = {
    attributes: attrs,
    file: fs.createReadStream('filename.txt'),
  };
  const files = await client.uploads.uploadFile(body);
  const file = files.entries[0];
  console.log(`File uploaded with id ${file.id}, name ${file.name}`);
  ```

  ```python Python v10 theme={null}
  client.uploads.upload_file(
      UploadFileAttributes(
          name=new_file_name, parent=UploadFileAttributesParentField(id="0")
      ),
      file_content_stream,
  )
  ```

  ```cs .NET v10 theme={null}
  await client.Uploads.UploadFileAsync(requestBody: new UploadFileRequestBody(attributes: new UploadFileRequestBodyAttributesField(name: newFileName, parent: new UploadFileRequestBodyAttributesParentField(id: "0")), file: fileContentStream));
  ```

  ```swift Swift v10 theme={null}
  // Create InputStream for a file based on URL
  guard let fileStream = InputStream(url: URL(string: "<URL_TO_YOUR_FILE>")!) else {
      fatalError("Could not read a file")
  }

  // Create a request body with the required parameters
  let requestBody = UploadFileRequestBody(
      attributes: UploadFileRequestBodyAttributesField(
          name: "filename.txt",
          parent: UploadFileRequestBodyAttributesFieldParentField(id: "0")
      ),
      file: fileStream
  )

  // Call uploadFile method
  let files = try await client.uploads.uploadFile(requestBody: requestBody)

  // Print some data from the reponse
  if let file = files.entries?[0] {
      print("File uploaded with id \(file.id), name \(file.name!)")
  }
  ```

  ```java Java v10 theme={null}
  client.getUploads().uploadFile(new UploadFileRequestBody(new UploadFileRequestBodyAttributesField(newFileName, new UploadFileRequestBodyAttributesParentField("0")), fileContentStream))
  ```

  ```java Java v5 theme={null}
  BoxFolder rootFolder = BoxFolder.getRootFolder(api);
  FileInputStream stream = new FileInputStream("My File.txt");
  BoxFile.Info newFileInfo = rootFolder.uploadFile(stream, "My File.txt");
  stream.close();
  ```

  ```python Python v4 theme={null}
  folder_id = '22222'
  new_file = client.folder(folder_id).upload('/home/me/document.pdf')
  print(f'File "{new_file.name}" uploaded to Box with file ID {new_file.id}')
  ```

  ```cs .NET v6 theme={null}
  using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
  {
      BoxFileRequest requestParams = new BoxFileRequest()
      {
          Name = uploadFileName,
          Parent = new BoxRequestEntity() { Id = "0" }
      };

      BoxFile file = await client.FilesManager.UploadAsync(requestParams, fileStream);
  }
  ```

  ```javascript Node v4 theme={null}
  var fs = require('fs');
  var stream = fs.createReadStream('/path/to/My File.pdf');
  var folderID = '0'
  client.files.uploadFile(folderID, 'My File.pdf', stream)
  	.then(file => {
  		/* file -> {
  			total_count: 1,
  			entries: 
  			[ { type: 'file',
  				id: '11111',
  				file_version: 
  					{ type: 'file_version',
  					id: '22222',
  					sha1: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' },
  				sequence_id: '0',
  				etag: '0',
  				sha1: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33',
  				name: 'My File.pdf',
  				description: '',
  				size: 68431,
  				path_collection: 
  					{ total_count: 1,
  					entries: 
  					[ { type: 'folder',
  						id: '0',
  						sequence_id: null,
  						etag: null,
  						name: 'All Files' } ] },
  				created_at: '2017-05-16T15:18:02-07:00',
  				modified_at: '2017-05-16T15:18:02-07:00',
  				trashed_at: null,
  				purged_at: null,
  				content_created_at: '2017-05-16T15:18:02-07:00',
  				content_modified_at: '2017-05-16T15:18:02-07:00',
  				created_by: 
  					{ type: 'user',
  					id: '33333',
  					name: 'Test User',
  					login: 'test@example.com' },
  				modified_by: 
  					{ type: 'user',
  					id: '33333',
  					name: 'Test User',
  					login: 'test@example.com' },
  				owned_by: 
  					{ type: 'user',
  					id: '33333',
  					name: 'Test User',
  					login: 'test@example.com' },
  				shared_link: null,
  				parent: 
  					{ type: 'folder',
  					id: '0',
  					sequence_id: null,
  					etag: null,
  					name: 'All Files' }
  				item_status: 'active' } ] }
  		*/
  	});
  ```
</CodeGroup>

<Info>
  **Preflight check**

  To prevent wasting time and bandwidth uploading a file that is going to be
  rejected it is recommended to perform a <Link href="/guides/uploads/check">pre-flight check</Link> before
  uploading the file.
</Info>

## Request Format

The request body of this API uses a content type of  `multipart/form-data`. This
is used to transmit two parts, namely the file attributes and the file's actual
content.

The first part is called `attributes` and contains a JSON object with
information about the file, including the name of the file and the `id` of the
parent folder.

The following is an example a `test.txt` being uploaded to the root folder of
the user.

```sh theme={null}
POST /api/2.0/files/content HTTP/1.1
Host: upload.box.com
Authorization: Bearer [ACCESS_TOKEN]
content-length: 343
content-type: multipart/form-data; boundary=------------------------9fd09388d840fef1

--------------------------9fd09388d840fef1
content-disposition: form-data; name="attributes"

{"name":"test.txt", "parent":{"id":"0"}}
--------------------------9fd09388d840fef1
content-disposition: form-data; name="file"; filename="test.txt"
content-type: text/plain

Test file text.

--------------------------9fd09388d840fef1--
```

<Warning>
  The `attributes` JSON part of the multi-part body must come before the `file`
  part of the multipart form data. When out of order, the API will return a HTTP
  `400` status code with an error code of `metadata_after_file_contents`.
</Warning>

## Options

To learn more about all the parameters available when uploading files, head over
to the <Link href="/reference/post-files-content">reference documentation for this API call</Link>. These parameters
include a `content-md5` that can be set to ensure a file is not corrupted in
transit, and the ability to explicitly specify the file creation time at a
different time than the upload time.

## Restrictions

Direct uploads are limited to a maximum file size of 50MB. For larger files,
please use the <Link href="/guides/uploads/chunked">chunked upload APIs</Link>.

Upload limits are dictated by the type of account of the authenticated user.
More information can be found <Link href="https://support.box.com/hc/en-us/articles/360043697314-Understand-the-Maximum-File-Size-You-Can-Upload-to-Box">in our product documentation on this topic</Link>.

<RelatedLinks
  title="RELATED APIS"
  items={[
{ label: translate("Preflight check before upload"), href: "/reference/options-files-content", badge: "OPTIONS" },
{ label: translate("Upload file"), href: "/reference/post-files-content", badge: "POST" }
]}
/>
