PutFileCommand

Adds or updates a file in a branch in an CodeCommit repository, and generates a commit for the addition in the specified branch.

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { CodeCommitClient, PutFileCommand } from "@aws-sdk/client-codecommit"; // ES Modules import
// const { CodeCommitClient, PutFileCommand } = require("@aws-sdk/client-codecommit"); // CommonJS import
const client = new CodeCommitClient(config);
const input = { // PutFileInput
  repositoryName: "STRING_VALUE", // required
  branchName: "STRING_VALUE", // required
  fileContent: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")   // required
  filePath: "STRING_VALUE", // required
  fileMode: "EXECUTABLE" || "NORMAL" || "SYMLINK",
  parentCommitId: "STRING_VALUE",
  commitMessage: "STRING_VALUE",
  name: "STRING_VALUE",
  email: "STRING_VALUE",
};
const command = new PutFileCommand(input);
const response = await client.send(command);
// { // PutFileOutput
//   commitId: "STRING_VALUE", // required
//   blobId: "STRING_VALUE", // required
//   treeId: "STRING_VALUE", // required
// };

PutFileCommand Input

See PutFileCommandInput for more details

Parameter
Type
Description
branchName
Required
string | undefined

The name of the branch where you want to add or update the file. If this is an empty repository, this branch is created.

fileContent
Required
Uint8Array | undefined

The content of the file, in binary object format.

filePath
Required
string | undefined

The name of the file you want to add or update, including the relative path to the file in the repository.

If the path does not currently exist in the repository, the path is created as part of adding the file.

repositoryName
Required
string | undefined

The name of the repository where you want to add or update the file.

commitMessage
string | undefined

A message about why this file was added or updated. Although it is optional, a message makes the commit history for your repository more useful.

email
string | undefined

An email address for the person adding or updating the file.

fileMode
FileModeTypeEnum | undefined

The file mode permissions of the blob. Valid file mode permissions are listed here.

name
string | undefined

The name of the person adding or updating the file. Although it is optional, a name makes the commit history for your repository more useful.

parentCommitId
string | undefined

The full commit ID of the head commit in the branch where you want to add or update the file. If this is an empty repository, no commit ID is required. If this is not an empty repository, a commit ID is required.

The commit ID must match the ID of the head commit at the time of the operation. Otherwise, an error occurs, and the file is not added or updated.

PutFileCommand Output

See PutFileCommandOutput for details

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
blobId
Required
string | undefined

The ID of the blob, which is its SHA-1 pointer.

commitId
Required
string | undefined

The full SHA ID of the commit that contains this file change.

treeId
Required
string | undefined

The full SHA-1 pointer of the tree information for the commit that contains this file change.

Throws

Name
Fault
Details
BranchDoesNotExistException
client

The specified branch does not exist.

BranchNameIsTagNameException
client

The specified branch name is not valid because it is a tag name. Enter the name of a branch in the repository. For a list of valid branch names, use ListBranches.

BranchNameRequiredException
client

A branch name is required, but was not specified.

CommitMessageLengthExceededException
client

The commit message is too long. Provide a shorter string.

DirectoryNameConflictsWithFileNameException
client

A file cannot be added to the repository because the specified path name has the same name as a file that already exists in this repository. Either provide a different name for the file, or specify a different path for the file.

EncryptionIntegrityChecksFailedException
server

An encryption integrity check failed.

EncryptionKeyAccessDeniedException
client

An encryption key could not be accessed.

EncryptionKeyDisabledException
client

The encryption key is disabled.

EncryptionKeyNotFoundException
client

No encryption key was found.

EncryptionKeyUnavailableException
client

The encryption key is not available.

FileContentRequiredException
client

The file cannot be added because it is empty. Empty files cannot be added to the repository with this API.

FileContentSizeLimitExceededException
client

The file cannot be added because it is too large. The maximum file size is 6 MB, and the combined file content change size is 7 MB. Consider making these changes using a Git client.

FileNameConflictsWithDirectoryNameException
client

A file cannot be added to the repository because the specified file name has the same name as a directory in this repository. Either provide another name for the file, or add the file in a directory that does not match the file name.

FilePathConflictsWithSubmodulePathException
client

The commit cannot be created because a specified file path points to a submodule. Verify that the destination files have valid file paths that do not point to a submodule.

FolderContentSizeLimitExceededException
client

The commit cannot be created because at least one of the overall changes in the commit results in a folder whose contents exceed the limit of 6 MB. Either reduce the number and size of your changes, or split the changes across multiple folders.

InvalidBranchNameException
client

The specified reference name is not valid.

InvalidDeletionParameterException
client

The specified deletion parameter is not valid.

InvalidEmailException
client

The specified email address either contains one or more characters that are not allowed, or it exceeds the maximum number of characters allowed for an email address.

InvalidFileModeException
client

The specified file mode permission is not valid. For a list of valid file mode permissions, see PutFile.

InvalidParentCommitIdException
client

The parent commit ID is not valid. The commit ID cannot be empty, and must match the head commit ID for the branch of the repository where you want to add or update a file.

InvalidPathException
client

The specified path is not valid.

InvalidRepositoryNameException
client

A specified repository name is not valid.

This exception occurs only when a specified repository name is not valid. Other exceptions occur when a required repository parameter is missing, or when a specified repository does not exist.

NameLengthExceededException
client

The user name is not valid because it has exceeded the character limit for author names.

ParentCommitDoesNotExistException
client

The parent commit ID is not valid because it does not exist. The specified parent commit ID does not exist in the specified branch of the repository.

ParentCommitIdOutdatedException
client

The file could not be added because the provided parent commit ID is not the current tip of the specified branch. To view the full commit ID of the current head of the branch, use GetBranch.

ParentCommitIdRequiredException
client

A parent commit ID is required. To view the full commit ID of a branch in a repository, use GetBranch or a Git command (for example, git pull or git log).

PathRequiredException
client

The folderPath for a location cannot be null.

RepositoryDoesNotExistException
client

The specified repository does not exist.

RepositoryNameRequiredException
client

A repository name is required, but was not specified.

SameFileContentException
client

The file was not added or updated because the content of the file is exactly the same as the content of that file in the repository and branch that you specified.

CodeCommitServiceException
Base exception class for all service exceptions from CodeCommit service.