To work with Autodesk Viewer & Data API, the first is the model will need to be uploaded to Autodesk cloud and be translated there. The quick start tells more. We also call this process as ‘workflow’' of Viewer & Data API) and provided the demo code in a couple languages on Github such as .NET, Python, Android (Java), iOS etc.
API (Rest services) of workflow are much fewer than Client API, but it is very important as client can do nothing if the model is not translated correctly in the cloud.
Generally, we can use the service Status to know how the translation is working. The response Json ‘Status’ and ‘Progress’ indicate it. While sometimes, we like to use service Thumbnail to get the snapshot of the model to verify the status, also display it in the gallery, panel etc.
Recently I was ‘lucky’ to hit the a problem when I migrated my sample of workflow:
workflow-android-view.and.data.api
The sample can work well earlier last year. However, when I tried to get thumbnail, it failed with the error: 204. The help says:
- 204 – No Content, No thumbnails were generated - even though the transaction is complete
That normally means the translating (or say registration) does not work well.
I checked the process uploading and translating. Both return 200. no a clue tells which process is problematic, while the .NET sample works well:
workflow-dotnet-winform-view.and.data.api
Finally, I started to suspect whether the model on the cloud is problematic or not. So I used bucket service to get it back. The syntax is very simple:
GET /oss/v1/buckets/<bucket name>/objects/<obj name>
Note: <obj name> is not the urn. There are various ways to call such service. Here is a code snippet of .NET:
private void getObject()
{
const String strClient = "https://developer.api.autodesk.com";
RestClient _client = new RestClient(strClient);
/////
// the processes of get token and set token are ignored.
// refer to https://github.com/Developer-Autodesk/workflow-dotnet-winform-view.and.data.api
/////
// the model name
string myModelName;// = "clashtest.nwd";
RestRequest viewerReq = new RestRequest();
//service of download file
viewerReq.Resource = "oss/v1/buckets/xiaodongtestbucket/objects/" + myModelName;
viewerReq.Method = Method.GET;
viewerReq.AddParameter("Authorization",
"Bearer " +
_token,
ParameterType.HttpHeader);
IRestResponse viewerResp = _client.Execute(viewerReq);
if (viewerResp.StatusCode == System.Net.HttpStatusCode.OK)
{
//download the file
MemoryStream ms = new MemoryStream(viewerResp.RawBytes);
FileStream dumpFile = new FileStream("c:\\temp\\" + myModelName,
FileMode.Create,
FileAccess.ReadWrite);
ms.WriteTo(dumpFile);
ms.Close();
dumpFile.Close();
}
}
It really proved my guess. The model in the cloud is actually corrupted. That is why translating does not work well.
After a couple of investigation, the issue is: the sample uploaded the model in a format of multi-parts, however uploading service does not accept the content of multi-part, though the codes have explicitly set it as “application/stream”. I guess this restriction was not so strict, so the code worked in the past.
It would not mean all 204 error is because of multi-parts, but at least you could check uploading code firstly when you get 204. And the downloading would help you sometimes if you want to analyze the uploading.
Comments