0

I'm working with the OpenStack Swift API version 1, and am trying to upload a large file to their object storage using c# and DotNet 4.5 in Visual Studio 2015.

See their API documentation at http://developer.openstack.org/api-ref-objectstorage-v1.html in the Objects section under Create or replace object.

Following their example using curl, I was able to upload a small test file. Wireshark shows a very simple protocol with the PUT method, a couple of headers and the raw data:

curl -X PUT -H "X-Auth-Token: ab2716160b394f6aab337f1ea8e9378f" -H "Content-Length: 10" -H "Content-Type: application/octet-stream" -d "1234567890"  http://10.25.10.10:8080/v1/AUTH_70466e9f789744e8b0169d398b8492cd/Test/test.dat


PUT /v1/AUTH_70466e9f789744e8b0169d398b8492cd/Test/test.dat HTTP/1.1
User-Agent: curl/7.30.0
Host: 10.25.10.10:8080
Accept: */*
X-Auth-Token: ab2716160b394f6aab337f1ea8e9378f
Content-Length: 10
Content-Type: application/octet-stream

1234567890

HTTP/1.1 201 Created
Last-Modified: Tue, 27 Oct 2015 23:52:45 GMT
Content-Length: 0
Etag: e807f1fcf82d132f9bb018ca6738a19f
Content-Type: text/html; charset=UTF-8
X-Trans-Id: txfb6b1300b3834e178f0ae-0056300e4c
Date: Tue, 27 Oct 2015 23:52:44 GMT

The DotNet WebClient apparently supports only POST when uploading files via its UploadFileAsync method, so that's out. I've found many other upload examples, all using multipart-formdata and POST.

How do I create a PUT request that includes a large file's contents without having to read the file into a buffer?

I appreciate any tips or pointers to examples or documentation!

Alan
  • 3,715
  • 3
  • 39
  • 57
  • D'oh! A coworker told me to re-check the WebClient methods, and sure enough there's one called UploadFileTaskAsync (note the Task in the name), which DOES accept a "method" parameter. I'm trying that now. – Alan Oct 29 '15 at 01:12

1 Answers1

0

Turns out that WebClient has a method UploadFileTaskAsync that supports a method parameter which I can set to PUT.

Alan
  • 3,715
  • 3
  • 39
  • 57