Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Unable to upload artifact(android apk file) to downloads in bitbucket with curl

- curl -v -X POST --user "${BITBUCKET_REPO_OWNER}:${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"app/build/outputs/apk/debug/*.apk"

 

I am using the above curl statement as it is, but it's failing and giving me the following error

 

Warning: setting file app/build/outputs/apk/debug/*.apk failed!
Note: Unnecessary use of -X or --request, POST is already inferred. 

1 answer

1 accepted

1 vote
Answer accepted

Hello @deepak_rathi,

AFAIK, to upload an array with cURL you need to use another syntax, something like

curl -F 'files[]=@/path/to/first/file' -F 'files[]=@/path/to/second/file' ...

Hope this helps.

Cheers,
Daniil

I don't want to upload an array. I just want to upload a single apk file to the download section.

Further, I did not create an app password for auth, I was wondering from where it was being picked but later on understood that I have to create an app password and make an account variable, did that but still getting the error now.


Warning: setting file app/build/outputs/apk/debugQA/*.apk failed!
Enter host password for user '':

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 150 0 0 0 150 0 2083 --:--:-- --:--:-- --:--:-- 2083curl: (26) read function returned funny value

cURL doesn't understand the * symbol, the path has to be specific to a single file.

Enter host password for user '':

This line means your credentials are not passed in properly. In bash variables are not substituted when inside of double quotes – move them out (for credentials you don't need quotes at all).

Then add verbose logging (curl -v) and check what's inside of Authorization header – it should be a base64 encoded string of username:password string.

I have to create an app password and make an account variable

What do you mean by account variable here?

Cheers,
Daniil

Why the error message language is so difficult to understand, the should have been something like file not located/found at the given path or something.

I'll do changes.

By account varible i meant - I have to set BB_AUTH_STRING in account variable right? just as suggested by you -> "it should be a base64 encoded string of username:password string"

By account varible i meant - I have to set BB_AUTH_STRING in account variable right? just as suggested by you -> "it should be a base64 encoded string of username:password string"

No, I was saying that in the log it would be a base64 string. In terms of configuration, it is easier to set username and password separately in two different variables, then use them in your cURL command like this:

curl -u ${BB_USERNAME}:${BB_PASSWORD} ...

Cheers,
Daniil

Like deepak_rathi likes this

Hi Daniil

This is working as supposed to. Thank you!

One more question I have - can we rename the file here which is being uploaded to Downloads?

No worries :)

Yes, specify filename property like this:

curl ... --form 'files=@/path/to/file/foo.apk;filename=bar.apk'

This will upload it as bar.apk.

Cheers,
Daniil

Like deepak_rathi likes this

Ok, thanks Daniil!

There must be so much more to learn, could you please give me the link Daniil so I can read more and understand more.

Thank you so much for all your help!

No worries, glad to help :)

A link to what? So far I was just using Google to clarify curl options...

Cheers,
Daniil

A link where i could read all these curl options and their customization, there must a documentation from bitbucket i hope.

Well, curl is a very popular tool and it already has very detailed manuals (just an example, it is also available via man page) as well as heaps of articles, blog posts and various examples on the Internet.

As for Bitbucket, we have API documentation covering all endpoints of the public API. For instance here's the endpoint for uploading files to repository Downloads which we're talking about. Those pages sometimes refer to curl commands as an example, but way not for all endpoints and their features. We're working on improving our documentation though, so hopefully it will become better.

Cheers,
Daniil

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

2,135 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you