0

Does anybody know what the request body looks like if I want to use Nexus API to upload artifact to a repo?

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("admin123:password123"))
$header = @{authorization = "Basic $token" }

$body = @{
    'raw.dictionary' = '/TestArtifact/Prod/'
    'raw.asset1' = 'c:\temp\lenovo.zip'
    'raw.asset1.filename' = 'lenovo.zip'

} | Convertto-Json

Invoke-RestMethod -Method POST -Uri 'http://xx.xx.xxx.xxx:8081/service/rest/v1/components?repository=TestRepo' -ContentType 'application/json'-Body $body -Headers $header

I'm getting 'Invoke-RestMethod: Response status code does not indicate success: 415 (Unsupported Media Type)'

  • I can tell you what i think is wrong. You are not sending the asset. You are just sending a string and not the binary data of the file. That is probably why you are getting the 415 error. – ArcSet Jun 01 '20 at 23:16

1 Answers1

0

Lets try and figure this out.

The command looks like you are trying to do is

curl -v -u admin:admin123 -X POST 'http://localhost:8081/service/rest/v1/components?repository=maven-releases' -F maven2.groupId=com.google.guava -F maven2.artifactId=guava -F maven2.version=24.0-jre -F maven2.asset1=@guava-24.0-jre.jar -F maven2.asset1.extension=jar -F maven2.asset2=@guava-24.0-jre-sources.jar -F maven2.asset2.classifier=sources -F maven2.asset2.extension=jar

It looks like the main issue we have is that you didnt convert the file to bytes.

-F @[FileName] is a Binary File

The only change really needing to be done was changing

'raw.asset1' = 'c:\temp\lenovo.zip'

to

'raw.asset1' = [System.IO.File]::ReadAllBytes("c:\temp\lenovo.zip")
ArcSet
  • 6,518
  • 1
  • 20
  • 34