0

I'm trying to load an image (.png) into my Gitlab project using an API call from powershell but it doesn't work

$token = "<my_access_token>"
$projectId = "5"
$file = "path\test.png"
$apiUrl = "https://gitlab.example.com/api/v4/projects/5/uploads"

Invoke-RestMethod -Uri $apiUrl -Method Post -Headers @{ "PRIVATE-TOKEN" = $token } -InFile $file -ContentType "image/png"

the error message is:

Invoke-RestMethod : {"error":"The provided content-type 'image/png' is not supported."} I have tried different options but I can't get it to work. Any suggestions?

Thanks

Manu
  • 81
  • 1
  • 3
  • From a quick look at the [docs](https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/projects.md#upload-a-file) you have to use content-type "multipart/form-data", but usually you don't have to specify that explicitly. I would first try with the curl example. For `Invoke-WebRequest` the parameter is `-form`. [Example](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.3#example-6-simplified-multipart-form-data-submission). – zett42 Jun 23 '23 at 08:56
  • Not all servers are the same. The server you are connecting to does not like the "image/png" for content type. You need to use a different content type that the server will accept. – jdweng Jun 23 '23 at 14:16

0 Answers0