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();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.