< Bitbucket
Files are typically uploaded to a remote git repository using git push
, however, Bitbucket also supports uploading files using a REST API.
Prerequisites
- Complete the Bitbucket/Get Started tutorial to create a Bitbucket account and learn how to create a repository and add files.
- Create a repository.
Readings
Upload a File to the Downloads Folder
Bitbucket has a Downloads folder which supports uploading and downloading files. This provides easy uploading and downloading, but files are not part of the repository source.
- Using the Bitbucket website, select the repository.
- On the left, select the Downloads folder.
- Select Add Files to add files. Files may be accessed or referenced using the full file URL.
Upload a File Using cURL
Files may be uploaded as source files using a command-line interface (CLI). Users comfortable with a CLI may use cURL.
- cURL is included in Linux and macOS. Windows users must download cURL from Haxx.se: curl.
- Open a terminal or command prompt window and navigate to the folder that contains the file to be uploaded.
- Use the following command to upload a file, replacing username, password, myaccount, myrepo, and filename.ext:
curl -u username:password -X POST https://api.bitbucket.org/2.0/repositories/myaccount/myrepo/src -F filename.ext=@filename.ext
For example:curl -u example:pass -X POST https://api.bitbucket.org/2.0/repositories/example/example.bitbucket.io/src -F example.jpg=@example.jpg
- Check your Bitbucket repository to verify that the file was uploaded successfully.
Upload a File Using Insomnia REST Client
Files may be uploaded as source files using a REST API. Users preferring a graphic user interface (GUI) may use the Insomnia REST client.
- Download and install Insomnia from Insomnia: REST Client.
- Run Insomnia.
- Create a new request. Name the request
Bitbucket Upload
, selectPOST
as the request type, andMultipart
as the content type. - At the top, enter
https://api.bitbucket.org/2.0/repositories/myaccount/myrepo/src
for the URL, replacing myaccount and myrepo with your Bitbucket account and repository name. - Under Multipart, enter
filename.ext
for the new name, replacingfilename.ext
with the filename and extension of your file. SelectFile
as the value and useChoose File
to select the file. - Under
Auth
, selectBasic Auth
and enter your Bitbucket username and password. - Send the request.
- Check your Bitbucket repository to verify that the file was uploaded successfully.
See Also
This article is issued from Wikiversity. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.