Request

Response

    Task 2 – Upload Source File to OSS

    The Object Storage Service (OSS) is a generic Cloud Storage Service that is part of the Data Management API. In this task, you upload the model to translate to OSS. While you can use any model for this purpose, we recommend that you use the file box.ipt as the model to translate. You can download this file from the walkthrough_data folder of the GitHub repository containing the Postman Collection for this walkthrough.

    By the end of this task you will be able to:

    • Create a Bucket to store the files.
    • Obtain a signed URL to upload a file to the bucket.
    • Upload a file to the Bucket.
    • Obtain the URN of the uploaded file.
    • Convert the URN to a Base64-encoded URN.

    You will use the following operations in this task:

    OperationHTTP Request
    Create a Bucket POST /buckets
    Get a Signed URL to Upload a File GET /buckets/{bucketKey}/objects/{objectKey}/signeds3upload
    Finalize File Upload POST /buckets/{bucketKey}/objects/{objectKey}/signeds3upload

    Step 1 - Create a Bucket

    The first thing to do when using the OSS service is to create a Bucket. Once a Bucket is created, you can store files in it as Objects.

    Request

    curl -X POST \
        'https://developer.api.autodesk.com/oss/v2/buckets' \
        -H 'Authorization: Bearer <YOUR_ACCESS_TOKEN>' \
        -H 'Content-Type: application/json' \
        -H 'x-ads-region: US' \
        -d '{
            "bucketKey": "<YOUR_BUCKET_KEY>",
            "access": "full",
            "policyKey": "transient"
        }'
    
    Show More

    Notes:

    • You must specify a name for your Bucket. Replace <YOUR_BUCKET_KEY> with a name for the Bucket.
    • Bucket keys must consist of only lower case characters, numbers 0-9, and the underscore (_) character
    • The Bucket key must be unique throughout all of the OSS service. If the Bucket name is already in use (even by another user) the system returns a 409 Conflict error. In such a case, retry with another Bucket name.

    Response

    {
        "bucketKey": "<YOUR_BUCKET_KEY>",
        "bucketOwner": "<YOUR_CLIENT_ID>",
        "createdDate": 1571296694595,
        "permissions": [
            {
                "authId": "T05H372IE11Kmkksdh73ndj0qie2f6nib",
                "access": "full"
            }
        ],
        "policyKey": "transient"
    }
    
    Show More

    Step 2 - Obtain signed URL

    • To upload a file to an OSS bucket, you need to have a signed upload URL. To obtain a signed URL:

    Request

    curl -X GET \
        'https://developer.api.autodesk.com/oss/v2/buckets/<YOUR_BUCKET_KEY>/objects/<YOUR_OBJECT_KEY>/signeds3upload?minutesExpiration=<LIFESPAN_OF_URL>' \
        -H 'Authorization: Bearer <YOUR_ACCESS_TOKEN>' \
        -H 'Content-Type: application/json>'
    

    Notes:

    • Replace <YOUR_ACCESS_TOKEN> with the access token you obtained in Task 1.
    • Replace <LIFESPAN_OF_URL> with 10. This will ensure that the signed URL that is returned will be valid for 10 minutes.
    • Replace <YOUR_OBJECT_KEY> with box.ipt, which is the name of the file we recommend that you upload.

    Response

     {
         "uploadKey": "<YOUR_UPLOAD_KEY>",
         "uploadExpiration": "2022-04-08T00:00:00Z",
         "urlExpiration": "2022-04-06T17:59:46Z",
         "urls": ["<SIGNED_UPLOAD_URL>"],
         "location": "https://developer.api.autodesk.com/oss/v2/buckets/<YOUR_BUCKET_KEY>/objects/<YOUR_OBJECT_KEY>"
     }
    

    Note down the values returned for uploadKey <YOUR_UPLOAD_KEY> and urls <SIGNED_UPLOAD_URL>. You will use these values in subsequent requests.

    Step 3 - Upload the file

    1. Download the file box.ipt from https://github.com/autodesk-platform-services/aps-tutorial-postman/tree/master/ModelDerivative_01/walkthrough_data.
    2. Send a request to upload the file to the Bucket.

    Request

    curl -X PUT \
        '<SIGNED_UPLOAD_URL>'\
        --data-binary '@<PATH_TO_YOUR_FILE_TO_UPLOAD>'
    

    Step 4 - Finalize Upload

    To make the uploaded file available for download, you must finalize the upload. To complete the upload:

    Request

    curl -X POST \
        'https://developer.api.autodesk.com/oss/v2/buckets/<YOUR_BUCKET_KEY>/objects/<YOUR_OBJECT_KEY>/signeds3upload' \
        -H 'Authorization: Bearer <YOUR_ACCESS_TOKEN>' \
        -H 'Content-Type: application/json' \
        -d '{
            "ossbucketKey": "<YOUR_BUCKET_KEY>",
            "ossSourceFileObjectKey": "<YOUR_OBJECT_KEY>",
            "access": "full",
            "uploadKey": "<YOUR_UPLOAD_KEY>"
            }'
    
    Show More

    Response

    {
        "bucketKey": "<YOUR_BUCKET_KEY>",
        "objectId": "<YOUR_OBJECT_ID>",
        "objectKey": "<YOUR_OBJECT_KEY>",
        "size": "134656",
        "contentType": "application/octet-stream",
        "location": "https://developer.api.autodesk.com/oss/v2/buckets/bucketKey/objects/inputfile",
        "permissions": [
            {
                "authId": "<YOUR_ACCESS_TOKEN>",
                "access": "full"
            }
        ],
        "policyKey": "transient"
    }
    
    Show More

    Step 3 - Convert the Source File URN to a Base64-encoded URN

    Most Model Derivative requests require the URN of the source file to be a Base64-encoded URN.

    • Use this online tool to convert the URN of the source file (The value of objectId you obtained in the previous step).

    For further information, see the full list of Base64 variants.

    We recommend using the unpadded option (RFC 6920), since it uses URL-safe alphabets. The following example shows a URN, its Base64-encoded form, and its URL safe Base64-encoded form:

    raw
    urn:adsk.a360betadev:fs.file:business.lmvtest.DS5a730QTbf1122d0751814909a776d191611?version=12
    Base64
    dXJuOmFkc2suYTM2MGJldGFkZXY6ZnMuZmlsZTpidXNpbmVzcy5sbXZ0ZXN0LkRTNWE3MzBRVGJmMTEyMmQwNzUxODE0OTA5YTc3NmQxOTE2MTE/dmVyc2lvbj0xMg==
    URL-safe Base64 (no padding)
    dXJuOmFkc2suYTM2MGJldGFkZXY6ZnMuZmlsZTpidXNpbmVzcy5sbXZ0ZXN0LkRTNWE3MzBRVGJmMTEyMmQwNzUxODE0OTA5YTc3NmQxOTE2MTE_dmVyc2lvbj0xMg