mcgregor94086
mcgregor94086

Reputation: 1529

Unable to add image files to new photoscene [autodesk-forge] API Reality Capture

I am having problems getting Autodesk Forge API to accept my files into a photoscene. The error message I get from the API call is:

{"developerMessage":"Access token provided is invalid or expired.", "moreInfo": "https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/", "errorCode": ""}

This error confuses me, as it comes immediately after I have just used this same forge_access_token successfully to create the photoscene I am adding these files to.

And the ""errorCode": "" section provides me no clues about what is wrong.

Here is the code sequence in my program:

  1. Get the forge_access_token,
  2. Create the photoscene, and
  3. Add image files to the photoscene.

1. I'm successfully getting an access_token with this code:

# Request for a 2-legged OAuth access token
json=`curl -s $FORGE_URL/authentication/v1/authenticate \
    -d client_id=$CLIENT_ID\
    -d client_secret=$CLIENT_SECRET\
    -d grant_type=client_credentials\
    -d scope=data:read+data:write
`
forge_access_token=`echo $json | jq -r .access_token`
echo "forge_access_token: $forge_access_token"

2. I then use the returned forge_access_token in the following code to successfully request a new photosceneid:

json=`curl -s $FORGE_URL/photo-to-3d/v1/photoscene \
    -X 'POST' \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $forge_access_token" \
    -d "scenename=$scan_id" \
    -d 'scenetype=object' \
    -d 'format=obj,rcm'
`
# echo $json
photosceneid=`echo $json | jq -r .Photoscene.photosceneid`
echo "Created Photoscene: $photosceneid"

3. But when I call this code to add image files to this new photoscene, it fails to add them:

JPG_FILES=$scan_dir/*.jpg
i=0
for image_file in $JPG_FILES
do
    file_name=`basename $image_file`    
    json=`curl -s $FORGE_URL/photo-to-3d/v1/file \
        -H 'Authorization: Bearer $forge_access_token' \
        -d 'photosceneid=$photosceneid' \
        -d 'type=image' \
        -d 'file[$i]=$image_file' 
    `
    i=$((i+1))

I am failing with this error message:

{"developerMessage":"Access token provided is invalid or expired.", "moreInfo": "https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/", "errorCode": ""}

Have any other Forge Reality Capture API users seen this? How did you solve it?

Upvotes: 0

Views: 158

Answers (2)

mcgregor94086
mcgregor94086

Reputation: 1529

The problem was in how BASH handles single and double quotes. BASH doesn't substitute the values for $variable if they occur in single quotes, instead of double quotes.

The following rewrite of the final section removed the "Access token provided is invalid or expired." error:

JPG_FILES=$scan_dir/*.jpg
i=0
for image_file in $JPG_FILES
do
    file_name=`basename $image_file`    
    json=`curl -s $FORGE_URL/photo-to-3d/v1/file \
        -H "Authorization: Bearer $forge_access_token" \
        -d "photosceneid=$photosceneid" \
        -d 'type=image' \
        -d "file[$i]=$image_file" 
    `
    i=$((i+1))

After fixing the above code by switching to double quotes, I am now having a NEW problem with uploading files, that I will post as a new question since it is different from the above.

Upvotes: 0

Petr Broz
Petr Broz

Reputation: 9942

How long does it take to upload all the JPEG files? The access token is usually set to expire in one hour so if there are too many images or they are too large, it's possible that the token expires before everything is uploaded.

Also, consider using curl with the -v flag so that you also see the exact request headers that are being sent, just to make sure that there's nothing funky happening with the $forge_access_token interpolation.

If it's neither of the issues above, please contact us via forge (dot) help (at) autodesk (dot) com - with as many details about your situation as possible - and we will pass it on to the engineering team.

Upvotes: 0

Related Questions