Issues with file upload

I an running the following code:
var restrequest = new RestRequest(“1.0/containers/” + container + “/files”, Method.POST);
restrequest.AddQueryParameter(“path”, path);
restrequest.AddFile(fileName, localFile);
restrequest.AddHeader(“X-LXD-uid”, “0”);
restrequest.AddHeader(“X-LXD-gid”, “0”);
restrequest.AddHeader(“X-LXD-mode”, “0700”);
restrequest.AddHeader(“X-LXD-type”, “file”);
restrequest.AddHeader(“X-LXD-write”, “overwrite”);
IRestResponse response = client.Execute(restrequest);
This creates a file with the correct name, however the content is missing.

Beware of this api, there are well known limitations such as having a too big file or downloading a file in /tmp coming from the fact that it is using a temp file and that symbolic links are forbidden.
So you should test the file and dest file name used with lxc file pull to ensure that it should work.
Then if that’s not the problem, you can debug it by setting your own computer as a remote and using tcpdump on lo interface, you will be able to compare lxc file pull and your software.

Content-Type issue perhaps?

@stgraber what should i specify as content-type for a text file?

Try application/octet-stream.

The issue you may be running into is Go trying to be smart and reading the request body ahead of us getting to do so, setting the Content-Type prevents that behavior.

@stgraber In this case RestSharp sends multipart form requests for files. I specified content type as multipart form data manually as well, but to no result, the file is still empty.

multipart form would definitely be wrong and trigger Go to do something bad

Yep, using an octet stream works instead