< Bitbucket

Files are typically uploaded to a remote git repository using git push, however, Bitbucket also supports uploading files using a REST API.

Prerequisites

  1. Complete the Bitbucket/Get Started tutorial to create a Bitbucket account and learn how to create a repository and add files.
  2. Create a repository.

Readings

  1. Wikipedia: REST API
  2. Atlassian: Bitbucket API - src
  3. Wikipedia: cURL
  4. Insomnia: REST Client

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.

  1. Using the Bitbucket website, select the repository.
  2. On the left, select the Downloads folder.
  3. 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.

  1. cURL is included in Linux and macOS. Windows users must download cURL from Haxx.se: curl.
  2. Open a terminal or command prompt window and navigate to the folder that contains the file to be uploaded.
  3. 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
  4. 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.

  1. Download and install Insomnia from Insomnia: REST Client.
  2. Run Insomnia.
  3. Create a new request. Name the request Bitbucket Upload, select POST as the request type, and Multipart as the content type.
  4. 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.
  5. Under Multipart, enter filename.ext for the new name, replacing filename.ext with the filename and extension of your file. Select File as the value and use Choose File to select the file.
  6. Under Auth, select Basic Auth and enter your Bitbucket username and password.
  7. Send the request.
  8. 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.