# BB v7.2.0 LTS - PUT not allowed when trying to upload a file to a repo

**URL:** <https://community.developer.atlassian.com/t/bb-v7-2-0-lts-put-not-allowed-when-trying-to-upload-a-file-to-a-repo/68044>\
**Category:** Bitbucket Server\
**Tags:** rest-api\
**Created:** [March 30, 2023, 10:56am UTC](https://community.developer.atlassian.com/t/bb-v7-2-0-lts-put-not-allowed-when-trying-to-upload-a-file-to-a-repo/68044 "2023-03-30T10:56:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AleksandarAndonov](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@AleksandarAndonov](https://community.developer.atlassian.com/u/AleksandarAndonov)\
**Post date:** [March 30, 2023, 10:56am UTC](https://community.developer.atlassian.com/t/bb-v7-2-0-lts-put-not-allowed-when-trying-to-upload-a-file-to-a-repo/68044/1 "2023-03-30T10:56:04Z")

</div>

Dear team Bitbucket,

Using the API, specifically [REST Resources Provided By: Bitbucket Server - REST](https://docs.atlassian.com/bitbucket-server/rest/7.2.0/bitbucket-rest.html#idp206)

Here is the code I’m using

```auto
import requests as req, json, sys
from urllib3 import encode_multipart_formdata

try:
    net_pol = open(sys.argv[1]).read()
except:
    "Could not open the network policy file. Exiting."
    sys.exit(1)

repo = sys.argv[2]

token = ""
branch = "netpol"

# print("net_pol file is:", net_pol,"repo is", repo)

payload = {'content': ("networkPolicy.yaml", net_pol), 'message': "Automatically synthesized policy using NP-Guard", "branch": branch, "sourceCommitId": ""}
data, boundary = encode_multipart_formdata(payload)

headers = {}
headers["Content-Type"] = boundary
headers["Authorization"] = f"Bearer {token}"

res = req.put(f"https://bitbucket.local:8443/projects/myproject/repos/{repo}/browse/helm-chart/templates/networkPolicy.yaml", data=data, headers=headers, verify=False)
if res.status_code != 201:
    print("Could not upload the policy.")
    print(res.request.body)
    print(res.content)
    sys.exit(1)

```

The server returns 405 for a POST request as well.

Similar to the issue 63377 from last year BUT I am using form data.

Please assist.

Thank you.

---

<div class="post-metadata">

**Author:** ![AleksandarAndonov](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@AleksandarAndonov](https://community.developer.atlassian.com/u/AleksandarAndonov)\
**Post date:** [April 10, 2023, 7:28am UTC](https://community.developer.atlassian.com/t/bb-v7-2-0-lts-put-not-allowed-when-trying-to-upload-a-file-to-a-repo/68044/2 "2023-04-10T07:28:56Z")

</div>

UPDATE  
I realised that I missed the ReST URL “rest/api/1.0”. I tried with it as well - it is not possible to add the new content.

```auto
404
b'{"errors":[{"context":null,"message":"Network/tags-management-new.yaml could not be edited because the file has been deleted on the branch.","exceptionName":"com.atlassian.bitbucket.content.NoSuchPathException"}]}'

```

Yes, it’s true - the file is not there. I need the server to create it.

I also tried different branches in case there’s an implicit protection of the main branch - doesn’t work.

Please assist.

---

<div class="post-metadata">

**Author:** ![AleksandarAndonov](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@AleksandarAndonov](https://community.developer.atlassian.com/u/AleksandarAndonov)\
**Post date:** [April 11, 2023, 9:10am UTC](https://community.developer.atlassian.com/t/bb-v7-2-0-lts-put-not-allowed-when-trying-to-upload-a-file-to-a-repo/68044/3 "2023-04-11T09:10:49Z")

</div>

From the way the server responds it is clear that PUT is only for editing, not for creating.

However, POST is not allowed.

Is it possible to upload a new file - has it been implemented?

Thank you

---

<div class="post-metadata">

**Author:** ![AleksandarAndonov](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@AleksandarAndonov](https://community.developer.atlassian.com/u/AleksandarAndonov)\
**Post date:** [November 27, 2023, 12:13pm UTC](https://community.developer.atlassian.com/t/bb-v7-2-0-lts-put-not-allowed-when-trying-to-upload-a-file-to-a-repo/68044/4 "2023-11-27T12:13:57Z")

</div>

Dear customer support,

Can you answer this question - Bitbucket Server offers the capability to create a new file via the API? Is it really implemented?
