Bitbucket/Uploading Files
Appearance
Files are typically uploaded to a remote git repository using git push
, however, Bitbucket also supports uploading files using a REST API.
Bitbucket also offers a free program called Sourcetree that can manage file uploads (and other pull requests) visually.
Prerequisites
[edit | edit source]- 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
[edit | edit source]Upload a File to the Downloads Folder
[edit | edit source]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
[edit | edit source]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 or use a tool that includes it (such as Git Bash).
- 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 the username, password, account name, repo path, and filename:
curl -u username:password -X POST https://api.bitbucket.org/2.0/repositories/myaccount/myrepo/src -F repo-filename.ext=@local-filename.ext
- Check your Bitbucket repository to verify that the file was uploaded successfully. Note that some files may take up to several minutes to appear.
Examples
[edit | edit source]- Upload example.jpg to the root folder:
curl -u example:pass -X POST https://api.bitbucket.org/2.0/repositories/example/example.bitbucket.io/src -F example.jpg=@example.jpg
- Upload example.jpg to the assets folder with a different filename:
curl -u example:pass -X POST https://api.bitbucket.org/2.0/repositories/example/example.bitbucket.io/src -F assets/flowers.jpg=@example.jpg
Upload a File Using Insomnia REST Client
[edit | edit source]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.