0

I am attempting to upload a DWF to my forge app's bucket (already created and functioning properly) from disk in C# using RestSharp

I get a successful response from my PUT request, but when I try to translate the DWF using the model derivative API, the manifest for the job returns a failed status, with an error code "DWF2D-Not_A_DWF_Error"

I have not had good luck finding examples to reference (most are in curl or deal with model content already on bim360)

Any ideas what could be wrong with my PUT request to upload to bucket?

byte[] byteFile = GetBinaryFile($"C:\\temp\\RoomView_{this.guid}.dwf");
RestClient client = new RestClient($"https://developer.api.autodesk.com/oss/v2/buckets/{this._bucket_key}/objects/RoomView_{this.guid}.dwf");
RestRequest request = new RestRequest(Method.PUT);
request.AddHeader("Authorization", "Bearer " + _auth_token.access_token);
request.AddHeader("Content-Length", byteFile.Length.ToString());
request.AddParameter("application/octet-stream", byteFile);

var response = client.Execute(request);

GetBinaryFile looks like this:

private byte[] GetBinaryFile(string filename)
    {
        byte[] bytes;
        using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read))
        {
            bytes = new byte[file.Length];
            file.Read(bytes, 0, (int)file.Length);
        }
        return bytes;
    }
r.schmitt
  • 53
  • 1
  • 10
  • replaced `request.AddParameter("application/octet-stream", byteFile);` with `request.AddParameter("requestBody", byteFile, ParameterType.RequestBody);` and now it works, – r.schmitt Mar 14 '19 at 18:51

2 Answers2

0

You can upload using the Forge .NET package, and you can find a sample here (resumable). This should be easier than using RestSharp...

Update

Using only restsharp, something like this:

    request.AddHeader("Content-Type", MimeType(filePath));
    request.AddHeader("Content-Disposition", string.Format("file; filename=\"{0}\"", Path.GetFileNameWithoutExtension(filePath)));
    request.AddParameter(MimeType(filePath), File.ReadAllBytes(filePath), ParameterType.RequestBody);
Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • i want to keep this light weight, the forge .net package is full of useless bloat and the code sample you linked to is longer than my entire application for just the upload request. I think using rest sharp is much simpler. Please try to answer my question if you can – r.schmitt Mar 11 '19 at 20:27
  • sorry about that, the Nuget package is **just** the code (no samples or other things). I'll give it a try with RestSharp – Augusto Goncalves Mar 11 '19 at 20:28
0

replaced request.AddParameter("application/octet-stream", byteFile); with request.AddParameter("requestBody", byteFile, ParameterType.RequestBody); and now it works,

r.schmitt
  • 53
  • 1
  • 10