Expand my Community achievements bar.

SOLVED

AEM Cloud - HTTP API - Asset Upload - 400 Invalid recursion selector value 'initiateUpload'

Avatar

Level 2

Hi there,

 

I'm trying to build a small app that leverages the HTTP API explained here to upload assets to our Cloud AEM instance:

 

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/assets/admin/develo...

 

When I execute the initial HTTP request via Postman, I'm getting a response back, but it's just this:

 

pcardno_0-1662070184782.png

[{"fileName":"apologies-i-have-none.jpg"}]

 

I've tested connectivity to the API by calling other parts of it using Basic Authentication, and that works fine.

 

When I try similar via the aem-upload node.js packages, I get failures but for different reasons. Using the script identified here:

https://github.com/adobe/aem-upload#uploading-files

 

 

// URL to the folder in AEM where assets will be uploaded. Folder
// must already exist.

// list of all local files that will be uploaded.
const uploadFiles = [
    {
        fileName: 'load.jpg', // name of the file as it will appear in AEM
        fileSize: 22537, // total size, in bytes, of the file
        filePath: 'C:\\Users\\uk003619\\source\\repos\\aemuploader\\load.jpg' // Full path to the local file
    }
];
 
const upload = new DirectBinary.DirectBinaryUpload({log: {
    debug: (...theArguments) => console.log.apply(null, theArguments),
    info: (...theArguments) => console.log.apply(null, theArguments),
    warn: (...theArguments) => console.log.apply(null, theArguments),
    error: (...theArguments) => console.log.apply(null, theArguments),
  }});
const options = new DirectBinary.DirectBinaryUploadOptions()
    .withUrl(targetUrl)
    .withUploadFiles(uploadFiles)
    .withBasicAuth('REDACTEDUSERNAME:REDACTEDPASSWORD');


// this call will upload the files. The method returns a Promise, which will be resolved
// when all files have uploaded.
upload.uploadFiles(options)
    .then(result => {
        console.log("success");
        console.log(JSON.stringify(result));
        // "result" contains various information about the upload process, including
        // performance metrics and errors that may have occurred for individual files

        // at this point, assuming no errors, there will be two new assets in AEM:
    })
    .catch(err => {
        console.log("error");
        console.log(JSON.stringify(err));
        // the Promise will reject if something causes the upload process to fail at
        // a high level. Note that individual file failures will NOT trigger this

        // "err" will be an instance of UploadError. See "Error Handling"
        // for more information
    });

 

This is the response:

 

PS C:\Users\uk003619\source\repos\aemuploader> node .\aemuploader.js
sending 1 files to httptransfer with options {
"uploadFiles": [
{
"fileUrl": "https://author-mmm-stage.adobecqms.net/content/dam/3m/testing/findabilitytest/type1/load.jpg",
"fileSize": 22537,
"filePath": "load.jpg"
}
],
"headers": {
"Authorization": "Basic cGF1bGNhcmRub3Rlc3RhcGl1c2VyOkFkb2JlQVBJR3JlZW5sMDBucys="
},
"concurrent": true,
"maxConcurrent": 5
}
Upload START 'load.jpg': 22537 bytes
1th failure event recorded: {"message":"Target AEM instance must have direct binary upload enabled","code":"ENOTSUPPORTED"}
Upload FAILED 'load.jpg': 'Target AEM instance must have direct binary upload enabled'
Closing all file handles
successfully uploaded files with httptransfer
Uploading result in JSON: {
"host": "https://author-mmm-stage.adobecqms.net",
"initSpent": 100,
"totalFiles": 1,
"totalTime": 898,
"totalCompleted": 1,
"finalSpent": 898,
"totalFileSize": 22537,
"avgFileSize": 22537,
"avgPutSpent": 1000,
"avgCompleteSpent": 200,
"nintyPercentileTotal": 1200,
"detailedResult": [
{
"fileName": "load.jpg",
"targetPath": "/content/dam/3m/testing/findabilitytest/type1/load.jpg",
"fileSize": 22537,
"partSize": 22537,
"fileSizeStr": "22.01 KB",
"partSizeStr": "22.01 KB",
"partNum": 1,
"putSpentFinal": 1000,
"putSpentMin": 1000,
"putSpentMax": 1000,
"putSpentAvg": 1000,
"completeSpent": 200,
"success": true,
"message": "",
"partDetails": [
{
"start": 0,
"end": 22537,
"message": "",
"elapsedTime": 1000,
"retryErrors": []
}
],
"retryErrors": []
}
],
"errors": [],
"retryErrors": []
}
success
{"host":"https://author-mmm-stage.adobecqms.net","initSpent":100,"totalFiles":1,"totalTime":898,"totalCompleted":1,"finalSpent":898,"totalFileSize":22537,"avgFileSize":22537,"avgPutSpent":1000,"avgCompleteSpent":200,"nintyPercentileTotal":1200,"detailedResult":[{"fileName":"load.jpg","targetPath":"/content/dam/3m/testing/findabilitytest/type1/load.jpg","fileSize":22537,"partSize":22537,"fileSizeStr":"22.01 KB","partSizeStr":"22.01 KB","partNum":1,"putSpentFinal":1000,"putSpentMin":1000,"putSpentMax":1000,"putSpentAvg":1000,"completeSpent":200,"success":true,"message":"","partDetails":[{"start":0,"end":22537,"message":"","elapsedTime":1000,"retryErrors":[]}],"retryErrors":[]}],"errors":[],"retryErrors":[]}
PS C:\Users\uk003619\source\repos\aemuploader>

 

Taking the other model described in there:

 

const DirectBinary = require('@adobe/aem-upload');

module.exports = {
    runstuff: async function () {
console.log("wyg");
//(async function () {
    console.log("yo");
const DirectBinary = require('@adobe/aem-upload');


const {
    FileSystemUploadOptions,
    FileSystemUpload
} = require('@adobe/aem-upload');
console.log("y1o");
// configure options to use basic authentication
const options = new FileSystemUploadOptions()
    .withBasicAuth('REDACTEDUSER:REDACTEDPASSWORD')
   
    console.log("yo2");
// upload a single asset and all assets in a given folder
const fileUpload = new FileSystemUpload({log: {
    debug: (...theArguments) => console.log.apply(null, theArguments),
    info: (...theArguments) => console.log.apply(null, theArguments),
    warn: (...theArguments) => console.log.apply(null, theArguments),
    error: (...theArguments) => console.log.apply(null, theArguments),
  }});
await fileUpload.upload(options, [
    'C:\\Users\\uk003619\\source\\repos\\aemuploader\\load.jpg'
]);

console.log("finished with the await");
    }
};
 
the result is similar:

 

PS C:\Users\uk003619\source\repos\aemuploader> node .\run.js
wyg
yo
y1o
yo2
Creating AEM directory /content/dam/3m with title ''
post https://author-mmm-stage.adobecqms.net/api/assets/3m < failed with status code 409
AEM folder '/content/dam/3m' already exists
Creating AEM directory /content/dam/3m/testing with title ''
post https://author-mmm-stage.adobecqms.net/api/assets/3m/testing < failed with status code 409
AEM folder '/content/dam/3m/testing' already exists
Creating AEM directory /content/dam/3m/testing/findabilitytest with title ''
post https://author-mmm-stage.adobecqms.net/api/assets/3m/testing/findabilitytest < failed with status code 409
AEM folder '/content/dam/3m/testing/findabilitytest' already exists
Creating AEM directory /content/dam/3m/testing/findabilitytest/type1 with title ''
post https://author-mmm-stage.adobecqms.net/api/assets/3m/testing/findabilitytest/type1 < failed with status code 409
AEM folder '/content/dam/3m/testing/findabilitytest/type1' already exists
From 1 paths, filesystem upload compiled upload of 0 directories, 1 files, with a total size of 22537. Encountered 0 filesystem-related errors.
Uploading 1 files
sending 1 files to httptransfer with options {
"uploadFiles": [
{
"fileUrl": "https://author-mmm-stage.adobecqms.net/content/dam/3m/testing/findabilitytest/type1/load.jpg",
"fileSize": 22537,
"filePath": "C:/Users/uk003619/source/repos/aemuploader/load.jpg"
}
],
"headers": {
"Authorization": "Basic cGF1bGNhcmRub3Rlc3RhcGl1c2VyOkFkb2JlQVBJR3JlZW5sMDBucys="
},
"concurrent": true,
"maxConcurrent": 5
}
Upload START 'load.jpg': 22537 bytes
1th failure event recorded: {"message":"Target AEM instance must have direct binary upload enabled","code":"ENOTSUPPORTED"}
Upload FAILED 'load.jpg': 'Target AEM instance must have direct binary upload enabled'
Closing all file handles
successfully uploaded files with httptransfer
Uploading result in JSON: {
"host": "https://author-mmm-stage.adobecqms.net",
"initSpent": 100,
"totalFiles": 1,
"totalTime": 537,
"totalCompleted": 1,
"finalSpent": 537,
"totalFileSize": 22537,
"avgFileSize": 22537,
"avgPutSpent": 1000,
"avgCompleteSpent": 200,
"nintyPercentileTotal": 1200,
"detailedResult": [
{
"fileName": "load.jpg",
"targetPath": "/content/dam/3m/testing/findabilitytest/type1/load.jpg",
"fileSize": 22537,
"partSize": 22537,
"fileSizeStr": "22.01 KB",
"partSizeStr": "22.01 KB",
"partNum": 1,
"putSpentFinal": 1000,
"putSpentMin": 1000,
"putSpentMax": 1000,
"putSpentAvg": 1000,
"completeSpent": 200,
"success": true,
"message": "",
"partDetails": [
{
"start": 0,
"end": 22537,
"message": "",
"elapsedTime": 1000,
"retryErrors": []
}
],
"retryErrors": []
}
],
"errors": [],
"retryErrors": []
}
finished with the await

 

 

 

We're using AEM as a Cloud Service, which in my understanding has direct binary upload supported by default. What am I missing? Do I need to enable something on our Cloud instance? 

1 Accepted Solution

Avatar

Correct answer by
Level 2

Apologies - when I originally started this post, I was getting the invalid recursion selector message, but I think I tracked that down to using HTTP rather than HTTPS in my call.

 

The issue being experienced now is exactly as described above, it just doesn't entirely match the title of this question.

View solution in original post

1 Reply

Avatar

Correct answer by
Level 2

Apologies - when I originally started this post, I was getting the invalid recursion selector message, but I think I tracked that down to using HTTP rather than HTTPS in my call.

 

The issue being experienced now is exactly as described above, it just doesn't entirely match the title of this question.