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

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

deepak_rathi March 25, 2020
- 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. 

2 answers

1 accepted

1 vote
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 26, 2020

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

deepak_rathi March 26, 2020

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

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 26, 2020

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

deepak_rathi March 28, 2020

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"

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 28, 2020

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
deepak_rathi March 30, 2020

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?

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 30, 2020

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
deepak_rathi March 30, 2020

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!

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 30, 2020

No worries, glad to help :)

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

Cheers,
Daniil

deepak_rathi April 1, 2020

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

Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 1, 2020

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

Nizamudeen Sherif
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 17, 2023

@deepak_rathi  Can you please share your entire Yaml File here? Am still facing the same problem you faced. 

0 votes
rikaz harrison
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 26, 2023

The provided curl statement for uploading an Android APK file to Bitbucket downloads has a syntax issue. The error indicates that setting the file using the wildcard "*.apk" is not supported. Instead, specify the exact file path without the wildcard. Modify the statement as follows:

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/your_app_name.apk"

Replace "your_app_name" with the actual name of your APK file. This should resolve the error and allow you to upload the artifact to Bitbucket downloads.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events