It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Bitbucket api upload zip file lost content any idea or help Edited

qaiser786 I'm New Here Jan 17, 2020

I am trying to upload a zip file via bitbucket org api. I tried to do this with postman, insomina, curl and php script. I am using the url https://api.bitbucket.org/2.0/repositories/{myAccount}/{myRepoName}/src and add the file according into client. 

 

For php script i used httpful for example. My problem is that the zip file is added successful with my commit message and the location where i want to add the file. but when i do git pull my_branch and i try to unzip the file it says "Unable to expand --fileName.zip--", It is in an unsupported format. 

 

Would appreciate if someone can help me out to understand and fix this issue. 

 

Thanks 

 

 

The Curl code is as follow 

 

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.bitbucket.org/2.0/repositories/Account/myrepo/src",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"481773-Pub_A-html.zip\"\r\n\r\n@/Users/user/Downloads/481773-Pub_A-html.zip\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"message\"\r\n\r\nzipfile from postman\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"Accept: */*",
"Accept-Encoding: gzip, deflate",
"Authorization: Basic token",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Content-Length: 353",
"Content-Type: multipart/form-data; boundary=--------------------------629401965265661450958266",
"Host: api.bitbucket.org",
"Postman-Token: 2f8d1349-540f-4a13-97f6-6a972075eda5,b693c61a-4423-41fc-aa19-4686bf3a2716",
"User-Agent: PostmanRuntime/7.20.1",
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

 

 

where as the php code is as 

 

$sourceFileInfo = $this-> getFileRealName($this->getFile());$url = sprintf("https://api.bitbucket.org/2.0/repositories/{$bitbucketSettings->userName}/{$bitbucketSettings->repoName}/src");        $base64 = base64_encode($bitbucketSettings->userName.':'.$bitbucketSettings->password);        $commitMessage = "This is the commit from my application";$body = array (
            'message' => $commitMessage,
            'file' => $sourceFileInfo['actualPath'],
            'branch' => $this->getSettings()->branch,
            'folder' => '/'.$bitbucketSettings->folder . '/'. $sourceFileInfo['realName']
        );$response = \Httpful\Request::post($url)
            ->addHeader('Authorization', "Basic $base64")
            ->addHeaders(                array(
                    'Accept-Encoding' => 'gzip, deflate',
                    'Host'  => 'api.bitbucket.org',
                    'Cache-Control' => 'no-cache',
                    'Accept' => '*/*',
                )
            )
            ->sendsType(Mime::FORM)
            ->body(
                'branch='.$body['branch'].
                "&message=" .$body['message'].
                "&{$body['folder']}=" .base64_encode(file_get_contents($body['file']))
            )
            -> send(); 

 

1 answer

Is it there any kind of content type issue? 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Bitbucket

Contest: Share your custom Bitbucket Pipe and win

Announced in this blog, this holiday season we’re celebrating all things CI/CD and between now and the end of 2019 we’ll be showcasing content, use cases, feature announcements and more. One featur...

999 views 4 4
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you