Search in sources :

Example 1 with PutFileResponse

use of software.amazon.awssdk.services.codecommit.model.PutFileResponse in project aws-doc-sdk-examples by awsdocs.

the class PutFile method uploadFile.

// snippet-start:[codecommit.java2.put_file.main]
public static void uploadFile(CodeCommitClient codeCommitClient, String filePath, String repoName, String branchName, String email, String name, String repoPath, String commitId) {
    try {
        // Create an SdkBytes object that represents the file to upload
        File myFile = new File(filePath);
        InputStream is = new FileInputStream(myFile);
        SdkBytes fileToUpload = SdkBytes.fromInputStream(is);
        PutFileRequest fileRequest = PutFileRequest.builder().fileContent(fileToUpload).repositoryName(repoName).commitMessage("Uploaded via the Java API").branchName(branchName).filePath(repoPath).parentCommitId(commitId).email(email).name(name).build();
        // Upload file to the branch
        PutFileResponse fileResponse = codeCommitClient.putFile(fileRequest);
        System.out.println("The commit ID is " + fileResponse.commitId());
    } catch (CodeCommitException | FileNotFoundException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : PutFileRequest(software.amazon.awssdk.services.codecommit.model.PutFileRequest) CodeCommitException(software.amazon.awssdk.services.codecommit.model.CodeCommitException) SdkBytes(software.amazon.awssdk.core.SdkBytes) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PutFileResponse(software.amazon.awssdk.services.codecommit.model.PutFileResponse) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 CodeCommitException (software.amazon.awssdk.services.codecommit.model.CodeCommitException)1 PutFileRequest (software.amazon.awssdk.services.codecommit.model.PutFileRequest)1 PutFileResponse (software.amazon.awssdk.services.codecommit.model.PutFileResponse)1