putFile method
Adds or updates a file in a branch in an AWS CodeCommit repository, and generates a commit for the addition in the specified branch.
May throw RepositoryNameRequiredException. May throw InvalidRepositoryNameException. May throw RepositoryDoesNotExistException. May throw ParentCommitIdRequiredException. May throw InvalidParentCommitIdException. May throw ParentCommitDoesNotExistException. May throw ParentCommitIdOutdatedException. May throw FileContentRequiredException. May throw FileContentSizeLimitExceededException. May throw FolderContentSizeLimitExceededException. May throw PathRequiredException. May throw InvalidPathException. May throw BranchNameRequiredException. May throw InvalidBranchNameException. May throw BranchDoesNotExistException. May throw BranchNameIsTagNameException. May throw InvalidFileModeException. May throw NameLengthExceededException. May throw InvalidEmailException. May throw CommitMessageLengthExceededException. May throw InvalidDeletionParameterException. May throw EncryptionIntegrityChecksFailedException. May throw EncryptionKeyAccessDeniedException. May throw EncryptionKeyDisabledException. May throw EncryptionKeyNotFoundException. May throw EncryptionKeyUnavailableException. May throw SameFileContentException. May throw FileNameConflictsWithDirectoryNameException. May throw DirectoryNameConflictsWithFileNameException. May throw FilePathConflictsWithSubmodulePathException.
Parameter branchName
:
The name of the branch where you want to add or update the file. If this
is an empty repository, this branch is created.
Parameter fileContent
:
The content of the file, in binary object format.
Parameter filePath
:
The name of the file you want to add or update, including the relative
path to the file in the repository.
Parameter repositoryName
:
The name of the repository where you want to add or update the file.
Parameter commitMessage
:
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.
Parameter email
:
An email address for the person adding or updating the file.
Parameter fileMode
:
The file mode permissions of the blob. Valid file mode permissions are
listed here.
Parameter name
:
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.
Parameter parentCommitId
:
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.
Implementation
Future<PutFileOutput> putFile({
required String branchName,
required Uint8List fileContent,
required String filePath,
required String repositoryName,
String? commitMessage,
String? email,
FileModeTypeEnum? fileMode,
String? name,
String? parentCommitId,
}) async {
ArgumentError.checkNotNull(branchName, 'branchName');
_s.validateStringLength(
'branchName',
branchName,
1,
256,
isRequired: true,
);
ArgumentError.checkNotNull(fileContent, 'fileContent');
ArgumentError.checkNotNull(filePath, 'filePath');
ArgumentError.checkNotNull(repositoryName, 'repositoryName');
_s.validateStringLength(
'repositoryName',
repositoryName,
1,
100,
isRequired: true,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'CodeCommit_20150413.PutFile'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'branchName': branchName,
'fileContent': base64Encode(fileContent),
'filePath': filePath,
'repositoryName': repositoryName,
if (commitMessage != null) 'commitMessage': commitMessage,
if (email != null) 'email': email,
if (fileMode != null) 'fileMode': fileMode.toValue(),
if (name != null) 'name': name,
if (parentCommitId != null) 'parentCommitId': parentCommitId,
},
);
return PutFileOutput.fromJson(jsonResponse.body);
}