Autodesk-Forge / forge-revit.ifc.scheduler

This code sample demonstrates the usage of Model Derivative API, which allows you to convert a Revit `.rvt` file stored in BIM 360 Docs to `.ifc` format.
Apache License 2.0
10 stars 4 forks source link

Call failed with status code 403 (Forbidden): PUT #3

Closed MilosAtBexel closed 4 months ago

MilosAtBexel commented 6 months ago

I have managed to connect scheduler app with my Autodesk Counstruction Cloud account. Did all the steps, application runs and i can see documents from ACC Docs. The issue is when i start the conversion of .rvt files to .ifc.

Here is the log from Conversion History:

[9:54 AM UTC] Created Job [9:54 AM UTC] Input JSON: [9:54 AM UTC] { "input": { "urn": "dXJuOmFkc2sud2lwZW1lYTpmcy5maWxlOnZmLkcxaWZvcWlnU2dtQXduQkw5TU5SRkE_dmVyc2lvbj0x", "compressedUrn": false, "rootFilename": "ML_ST-Demo_Building 03.rvt" }, "output": { "destination": { "region": "EMEA" }, "formats": [ { "type": "IFC", "advanced": { "exportSettingName": "IFC2x3 Coordination View 2.0" } } ] } } [9:54 AM UTC] Processing Model Derivative: 99% complete [9:55 AM UTC] Added Derivative URN from Manifest: urn:adsk.viewing:fs.file:dXJuOmFkc2sud2lwZW1lYTpmcy5maWxlOnZmLkcxaWZvcWlnU2dtQXduQkw5TU5SRkE_dmVyc2lvbj0x/output/Resource/IFC/ML_ST-Demo_Building 03.ifc [9:55 AM UTC] Received Conversion Job [9:55 AM UTC] Created Storage Location: urn:adsk.objects:os.object:wip.dm.emea.2/c431e78b-5d07-40b9-8784-470aedea88b2.ifc [9:55 AM UTC] Conversion Error: [9:54 AM UTC] Created Job [9:54 AM UTC] Input JSON: [9:54 AM UTC] { "input": { "urn": "dXJuOmFkc2sud2lwZW1lYTpmcy5maWxlOnZmLkcxaWZvcWlnU2dtQXduQkw5TU5SRkE_dmVyc2lvbj0x", "compressedUrn": false, "rootFilename": "ML_ST-Demo_Building 03.rvt" }, "output": { "destination": { "region": "EMEA" }, "formats": [ { "type": "IFC", "advanced": { "exportSettingName": "IFC2x3 Coordination View 2.0" } } ] } } [9:54 AM UTC] Processing Model Derivative: 99% complete [9:55 AM UTC] Added Derivative URN from Manifest: urn:adsk.viewing:fs.file:dXJuOmFkc2sud2lwZW1lYTpmcy5maWxlOnZmLkcxaWZvcWlnU2dtQXduQkw5TU5SRkE_dmVyc2lvbj0x/output/Resource/IFC/ML_ST-Demo_Building 03.ifc [9:55 AM UTC] Received Conversion Job [9:55 AM UTC] Created Storage Location: urn:adsk.objects:os.object:wip.dm.emea.2/c431e78b-5d07-40b9-8784-470aedea88b2.ifc Call failed with status code 403 (Forbidden): PUT https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/c431e78b-5d07-40b9-8784-470aedea88b2.ifc

I have full access, as Account Admin for the ACC project. Any idea why im i getting 403 Forbidden when trying to create storage location for the ifc?

MilosAtBexel commented 6 months ago

i found the part of the code that is giving me this error: `

string range = $"bytes={i}-{Math.Min(contentLength - 1, i + 5_000_000 - 1)}";
string uploadRange = $"bytes {i}-{Math.Min(contentLength - 1, i + 5_000_000 - 1)}/{contentLength}";

using Stream downloadStream = await downloadUrl
    .WithOAuthBearerToken(token)
    .WithHeader("Range", range)
    .GetStreamAsync(completionOption: HttpCompletionOption.ResponseHeadersRead);

var content = new StreamContent(downloadStream);

var response = await uploadStreamUrl
    .AppendPathSegment("resumable")
    .WithOAuthBearerToken(token)
    .WithHeader("Content-Range", uploadRange)
    .WithHeader("Session-Id", sessionId)
    .PutAsync(content);

if (response.StatusCode == StatusCodes.Status200OK)
{
    var jsonResponse = response.GetStringAsync().Result;
    dynamic data = JsonConvert.DeserializeObject<dynamic>(jsonResponse);

    objectId = data.objectId;
}

`

its in this method: PassDownloadToStorageLocation(...) it looks like the .ifc is downloaded to varibable content, but i get 403 when this is called: var response = await uploadStreamUrl .AppendPathSegment("resumable") .WithOAuthBearerToken(token) .WithHeader("Content-Range", uploadRange) .WithHeader("Session-Id", sessionId) .PutAsync(content);

yiskang commented 6 months ago

Thanks for reporting. This sample still uses some deprecated API, so it caused the error.

As our new SDK is coming, we have plans to migrate most of our samples to use the new one, but it would take time to complete.

However, we don't want to block you from using this sample, so if you want to fix this issue yourself, please follow this blog post to migrate to the new API:

https://aps.autodesk.com/blog/download-derivative-files-using-new-signedcookies-api-without-setting-cookies-first-header

Our apologies for the inconvenience!

MilosAtBexel commented 6 months ago

Thank you for the response. In the mean time i figured out that the upload api was depricated. So i tried implementing the new api for upload that uses Signed S3 URL from this specification: https://aps.autodesk.com/en/docs/bim360/v1/tutorials/document-management/upload-document-s3/

but when calling Step 6: Generate a Signed S3 URL i also get 403 error with ThreeLeggedAuth token. All the API-s that are called in previus steps are working with the same token.

I will try to make it work, but im currently running in circles. Will check your link and give feedback if it helps.

Do you have any estimate (weeks, months) when will you be updating the example code to use the new API so we can decide to wait for the update or try and resolve it ourselves?

yiskang commented 6 months ago

Not all upload tasks can work with three-legged access tokens. Here are the download/upload tasks in this sample as I know, so I would advise you to check which one reports the 403 errors.

Sorry, I don't have ETA yet, as we have many samples to be migrated together. In addition, there are some other things in this sample that must be migrated (e.g., React framework), except for the deprecated APS API migration. This sample was written by our consultant team, so it would also take me some time to understand its implementation. So, I'm afraid that would not be so soon...

yiskang commented 4 months ago

Sorry for the delay. The new and updated repo can be found here: https://github.com/autodesk-platform-services/aps-revit.ifc.scheduler