Search code examples
c#.netautodesk-forgeautodesk-bim360

How does the UploadObjectAsync() method work?


https://forge.autodesk.com/en/docs/bim360/v1/tutorials/documen-management/upload-document/

I am following the tutorial above to upload a file into a BIM 360 folder through Autodesk Forge. I have reached Step 6: Upload the File to the Storage Object and I am trying to use the method UploadObjectAsync() to upload a file but I am getting an error stating: error getting value from 'ReadTimeout' on 'System.Web.HttpInputStream' and I am unsure how to fix this.

Am I using the wrong method or there something I am missing in the code? Below is the method I am using on .NET.

HttpPostedFile file = req.Files[0];
ObjectsApi objectsApi = new ObjectsApi();
dynamic objects = await objectsApi.UploadObjectAsync(bucketKey, objectName, file.ContentLength, file.InputStream);

Solution

  • Try use the underlying stream of a StreamReader from the file to upload, instead of the raw InputStream from multipart form:

    using (StreamReader streamReader = new StreamReader(fileSavePath))
    {
        await objects.UploadObjectAsync(bucketKey, objectName,(int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream");
        ...
    }
    

    Given how the UploadObjectAsync and its chained method UploadObjectAsyncWith(code here) is implemented you'd better saved the posted file and then upload it instead of piping streams. See an example here.