Gitlab commit API - base64 data not writing to image

I am trying to upload an image to Gitlab via base64. Everything works fine (correct path, correct branch, filename, etc) but the image data is not being written and displays as broken.

I am using Axios to accomplish this my request.

var header = {
    'PRIVATE-TOKEN' : 'SuP3rS3Cr3T0kN'
};    

var commit = {
    branch: "master",
    commit_message: 'some message',
    actions: [
        {
            action: "create",
            encoding: "base64",
            file_path: 'images/' + filename,
            content: imgData
        }
    ]
};

axios.post('https://gitlab.com/api/v4/projects/'+ self.project.id +'/repository/commits', commit ,{
    headers: header
})
.then(function(res){
    console.log(res.data)
})
.catch(function(err){
    console.error(err);
});

Here is the example base64 data I am trying to write

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxATEBURExIVFhUWFhcYGRUXFRgVGRkdFRcXFhgYFRgaHSggGyAlGxgVLTIiJSkrLi4uGB8zODMsNygtLisBCgoKDg0OGxAQGy0iICUtMSstNzgtKy0tKy0vLS0uLS8vNy0vLS0tLS0vLS0tKy0tLy0tLS0tLS0tLS0tLS0tN//AABEIAIAAgAMBIgACEQEDEQH/xAAcAAABBQEBAQAAAAAAAAAAAAAFAAMEBgcCAQj/xABAEAACAAQCBgYIBAUDBQAAAAABAgADBBEFIQYSMUFRcSJhgZGhsQcTI1JiwdHwMkJy4RRjgpKyQ6LCFRYzc4P/xAAZAQEAAwEBAAAAAAAAAAAAAAADAAIEAQX/xAAoEQACAgECBAYDAQAAAAAAAAAAAQIRAyExEhMiQTJRYXGBsQRioRT/2gAMAwEAAhEDEQA/ANxhQoUQgoUKKppXptIpby19pO9wHJf1ndy28otGLk6RWUlFWy0TZqqCzEADaSbAczFVxX0g0Mq4VjNb+WLj+42HdeKHUfx9edefMKy9oW1l/pTfzPfBPD9HZC7E124t0vDZDcGOHidv0C45y8Kpeo9P9JlQ5tIpR/UWfwUCGP8AvTFzn6hR/wDJ/m0HZWGPa1go4fsId/6afeHdHObBbRR3ly7yK8NOMVXNqdSP/U/yaJdJ6TyDadTkcSjZ/wB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XEDKPG5EpmNyQbZKM8us2Fu+LLL9HMne0w8yPkIKUWg1Kmfqwf1Xbzi08+NqnbOY/x5xdlUn6WV9R0KaX6tdl16TdrnIdwiRg2hDu3rKhi5JuRcm5+JjmY0OlwhF2AQQlyQIB52lUFRoWHW5OwdhuFJLUAAADcBaCiraPYUAMKFChRCH/2Q==

I found that removing data:image/jpeg;base64, solved the problem as gitlab does not parse this for you.

1 Like