Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Rest API: posting a file on bitbucket loses its execution mode

laurens_brock
December 9, 2025

Hi,

 

I'm trying to alter an existing file on bitbucket using this rest call:
https://developer.atlassian.com/cloud/bitbucket/rest/api-group-source/#api-repositories-workspace-repo-slug-src-post

 

But whenever I change a file which has a +x modifier, it loses it after I run the post command.  The file change however does still go through. So I always get a 201 response.

So after the change, I checkout the branch to verify and I get the following result:
diff --git a/ci/build.sh b/ci/build.sh
old mode 100755
new mode 100644

I tried it with and without Content-Disposition, but it neither seem to work.

This is my last attempt:

```

def upload_files_to_repo(
    repo_slug: str, branch_name: str, file_contents: dict, commit_message: str
) -> bool:

    data = {"branch": branch_name, "message": commit_message}

    headers = get_header()
    headers.update({"Content-Disposition": 'attachment; filename="ci/build.sh"; x-attributes:"executable"'})
    url = f"https://api.bitbucket.org/2.0/repositories/{WORKSPACE_SLUG}/{repo_slug}/src"
    files = {file_path: file_content for file_path, file_content in file_contents.items()}

    response = requests.post(url, headers=headers, files=files, data=data)

```

Also doing something along the lines of this doesn't seem to work either:
```

url = f"https://api.bitbucket.org/2.0/repositories/{WORKSPACE}/{REPO_SLUG}/src"

m = MultipartEncoder(
fields={
"message": "Add shutdown script + symlink",
"branch": BRANCH,

# destination paths in the repo:
"bin/shutdown.sh": part(
"bin/shutdown.sh",
"shutdown.sh",
b"#!/bin/sh\nhalt\n",
"executable",
),
"README.txt": part(
"README.txt",
"README.txt",
b"README\n", # symlink target path :contentReference[oaicite:3]{index=3}
"link",
),
}
)

resp = requests.post(
url,
data=m,
headers={"Authorization": f"Bearer {ACCESS_TOKEN}", "Content-Type": m.content_type},
timeout=30,
)

```

 

Any help with some concrete examples would be appreciated.

 

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events