The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to commit multiple files from memory using bitbucket API?

Kurt Rhee
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 26, 2021

Hello I have been able to upload files to bitbucket cloud by saving them first to my disk and then commiting them one by one to my repository via the API, but I haven't been able to send files that are in memory and I haven't been able to send multiple files which should get committed to different folders at the same time.

Does anybody know how to do this?

I am writing my api functions in python using the requests library.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 23, 2021

Hi @Kurt Rhee 

Welcome to the community!

If I got this right you wish to use the API to create commit on multiple files from memory? If yes, I believe the following curl API endpoint can be used with the content type of multipart/form-data to commit multiple files:

curl --request POST \
  --url https://api.bitbucket.org/2.0/repositories/<WorkspaceID>/<RepoSlug>/src \
  --header 'Authorization: Basic cm9.....==' \
  --header 'Content-Type: multipart/form-data' \
  --form 'message=my commit message' \
  --form branch=<branch name> \
  --form file1=@<My First File Path>\
  --form directory/file2=@<My Second File Path>


As for using python, I am not an expert on this, but from my research on how to POST a file with Python and I found the following example:

import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder

m = MultipartEncoder(
    fields={
            'branch': 'dev', 
            'message': '<Your MESSAGE>',
            '/path/file1': ('filename', open('file1.py', 'rb'), 'text/plain'),
            '/path/file2': ('filename', open('file2.py', 'rb'), 'text/plain'),}
    )
....
....
r = requests.post(url, data=m, headers)

I hope this helps!

Cheers,
Syahrul

Kurt Rhee
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 24, 2021

Hello this is very helpful thank you!

Like Syahrul likes this
TAGS
AUG Leaders

Atlassian Community Events