Bitbucket REST API Post File Something went wrong
Asked by Alexandru Branescu:

Hello,

I am trying to push a file using the <https://api.bitbucket.org/2.0/repositories/{org}/{repo}/src> endpoint and I'm getting the following error

```
{

"type":"error",

"error": {

  "message":"Something went wrong",

  "id":"879686cc95a44e07959f4df58a5fb782"

  }

}
```

The file in question is a 2.6 Gb zip file. Trying to push a smaller archive results in success.

Trying the request in insomnia results in success, however, it takes 300+ seconds to POST.

Code used:  

```
$client = new Client();

$headers = [
  'Content-Type' => 'multipart/form-data'
];

$options = [
  'multipart' => [
    [
    'name' => ARCHIVE_NAME,
    'contents' => FILE_CONTENTS
    ],
    [
    'name' => 'message',
    'contents' => COMMIT_MESSAGE
    ]
  ]
];
$request = new Request('POST', 'https://api.bitbucket.org/2.0/repositories/{org}/{repo}/src', $headers);
$res = $client->sendAsync($request, $options)->wait();
```

cURL equivalent:

```
curl --request POST \
--url https://api.bitbucket.org/2.0/repositories/{org}/{repo}/src \
--header 'Authorization: Basic {token}' \
--header 'Content-Type: multipart/form-data' \
--form FILE_NAME=@FILE_PATH \
--form message=COMMIT_MESSAGE
```

Any suggestions would be greatly appreciated.


Answers:
author: Caroline R
body: Hi, [@Alexandru Branescu](/t5/user/viewprofilepage/user-id/5031237), welcome to the community!

Checking the id you shared with us, I can see it means a **RequestTimeoutError**.

Could you please tell me if you are versioning this 2.6 GB file? Because in case you are not, I would advise you to move this file to Git LFS. Here you can read more about how to use Git LFS on Bitbucket Cloud:

* [Use Git LFS with Bitbucket](https://support.atlassian.com/bitbucket-cloud/docs/use-git-lfs-with-bitbucket/)

Also, based on this public bug, it looks like we have a limitation on the size of the file we can upload through API:

* <https://jira.atlassian.com/browse/BCLOUD-18999>

I tested it myself and received the same error (RequestTimeoutError) using curl and Insomnia. However, I was able to add the file using a git push, but as I said before, we don't recommend keeping a file of this size in your repo, as if your repository reaches the 4GB limit, your ability to push to the repository will be disabled. You can read more about our limits in this document:

* [What kind of limits do you have on repository/file size?](https://support.atlassian.com/bitbucket-cloud/docs/what-kind-of-limits-do-you-have-on-repositoryfile-size/)

I hope this helps, but do let me know if you have any questions.

Kind regards,  
Caroline

comments: author: Alexandru Branescu
body: Hi [@Caroline R](/t5/user/viewprofilepage/user-id/3934006) ,

Thank you for your response. I used to be able to push the file using insomnia, but now I get the same error, so I guess the issue is recent.

We've reduced the size of the file to \~600 MB, but it still seems it exceeds the 500 MB limit.

We do not need versioning, we're generating the file from a web app and need it to be available in git to be pulled in our jenkins pipeline.

Could LFS be used with the rest API, and if so, could you please link some documentation for the usage?

Thank you,

Alex Branescu


author: Caroline R
body: Hi, [@Alexandru Branescu](/t5/user/viewprofilepage/user-id/5031237),

As you confirmed you do not need versioning and were able to reduce the file to \~600 MB, I would recommend you to upload this file to your repository using the **Downloads** section (you can simply access the **Downloads** section in your repository \> click **Add files** to upload this file), and then use our API endpoint to get the file in Jenkins:

* <https://developer.atlassian.com/cloud/bitbucket/rest/api-group-downloads/#api-group-downloads>

This is an example of a request you could follow:

```
curl -X GET -u XXX:XXX "https://api.bitbucket.org/2.0/repositories/{workspace}/{repo}/downloads/text.zip" >> zip_test.zip
```

Please let me know how it goes and feel free to ask any additional questions regarding this case.

Kind regards,  
Caroline


author: Alexandru Branescu
body: Extra debugging information after setting Guzzle Client debug to true:

```
* Connected to api.bitbucket.org (18.205.93.6) port 443 (#0) 
* ALPN, offering http/1.1 
* successfully set certificate verify locations: 
* CAfile: /etc/ssl/certs/ca-certificates.crt 
* CApath: /etc/ssl/certs 
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256 
* ALPN, server accepted to use http/1.1 
* Server certificate: 
* subject: C=US; ST=California; L=San Francisco; O=Atlassian, Inc.; CN=*.b 
itbucket.org 
* start date: Jul 1 00:00:00 2022 GMT 
* expire date: Jul 21 23:59:59 2023 GMT 
* subjectAltName: host "api.bitbucket.org" matched cert's "*.bitbucket.org 
" 
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High 
Assurance Server CA 
* SSL certificate verify ok. 
> POST /2.0/repositories/{org}/{repo}/src HTTP/1.1 
Host: api.bitbucket.org 
Expect: 100-Continue 
User-Agent: GuzzleHttp/6.5.5 curl/7.74.0 PHP/8.0.21 
Content-Type: multipart/form-data; boundary=6e12d08d-ea97-43cd-ba63-80da19e 
acd61 
Accept: application/json 
Authorization: Basic {token} 
Content-Length: 649360296 

* Mark bundle as not supporting multiuse 
< HTTP/1.1 100 Continue 
* We are completely uploaded and fine 
* Mark bundle as not supporting multiuse 
< HTTP/1.1 500 INTERNAL SERVER ERROR 
< Server: nginx 
< Vary: Authorization, Origin 
< Cache-Control: max-age=0, no-cache, no-store, must-revalidate 
< Content-Type: application/json; charset=utf-8 
< X-OAuth-Scopes: webhook, pullrequest:write, project, team, account 
< X-B3-TraceId: 915b79dcd8428168 
< X-Usage-Output-Ops: 2518832 
< X-Dc-Location: Micros-3 
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload 
< Date: Wed, 14 Sep 2022 17:23:54 GMT 
< X-Usage-User-Time: 29.324385 
< X-Usage-System-Time: 2.774709 
< X-Served-By: 4df28947ebce 
< Expires: Wed, 14 Sep 2022 17:23:54 GMT 
< X-Sentry-ID: 2ae380433bc54e3c92a21be477dce8f5 
< X-View-Name: bitbucket.apps.repo2.api.v20.src.CommitBuilderHandler 
< X-Static-Version: 8332847e6078 
< X-Accepted-OAuth-Scopes: repository:write 
< X-Credential-Type: apppassword 
< X-Render-Time: 38.111363887786865 
< Connection: close 
< X-Usage-Input-Ops: 24 
< X-Frame-Options: SAMEORIGIN 
< X-Version: 8332847e6078 
< X-Request-Count: 716 
< Content-Length: 99 
< 
* Closing connection 0 
```


Tags: bitbucket-cloud

cloud