Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

curl php post a file to repository - error 404

Vasilev November 18, 2020

Hello,

I am trying to upload a file to my private repository.

I have read:

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/src#post

https://stackoverflow.com/questions/20302524/upload-file-to-bitbucket-via-php-script

 

App password is created.

this is my code:

 

$file_git = "test.jpg";

$data_string_git = [  'files' => curl_file_create($file_git),];

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, "https://api.bitbucket.org/2.0/repositories/USERNAME/REPO/src/".urlencode("test.jpg"));  

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);   

curl_setopt($ch, CURLOPT_POST, 1);       

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");         

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string_git);       

curl_setopt($ch, CURLOPT_FAILONERROR, true);

curl_setopt($ch, CURLOPT_USERPWD, "USERNAME:APP_PASS");       

curl_setopt($ch, CURLAUTH_BASIC, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);       

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);       

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

$result = curl_exec($ch);

 

I am not sure should I specify additional data for the commit for example and author.

Can you please let me know where is the problem?

 

thank you

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events