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