1
votes

I'm trying to upload some files to my webapp using Kudu to the below url: https://($websitename.scm.azurewebsites.net/api/vfs/site/wwwroot/ using powershell

I have obtained the publishing username and password and can authenticate fine

However when i try to upload the files i'm getting the below error using the below code:

function Upload-FileToWebApp($kuduHeader,$KuduURL,$files)
{   
$kuduURL = https://$websitename.scm.azurewebsites.net/api/vfs/site/wwwroot/ 

 $result = Invoke-RestMethod -Uri $kuduUrl `
                    -Headers @{Authorization=$kuduheader;"If-Match"="*"} `
                    -Method PUT `
                    -InFile $files `
                    -ContentType "multipart/form-data"

Invoke-RestMethod : {"Message":"The resource represents a directory which can not be updated."}

I have tried to access this URL using the ARC chrome addin and this brings back the same error '409 conflict Message": "The resource represents a directory which can not be updated."

Get seems to work fine

Thanks in Advance!

1

1 Answers

0
votes

The problem is that you are doing a PUT on a directory, which has the semantic of creating the directory, when what you're trying to do is upload a file.

You need to change https://$websitename.scm.azurewebsites.net/api/vfs/site/wwwroot/ to https://$websitename.scm.azurewebsites.net/api/vfs/site/wwwroot/MyFile.txt.

And note that the vfs API can only upload one file at a time. If you want to upload multiple, you can use the zip API. See https://github.com/projectkudu/kudu/wiki/REST-API#zip for details.