adobe / adobe/aem-upload

not valid JSON while parsing '<html>\n`

Open
#115 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
68
Forks
18
PR merge metrics
No merged PRs in 30d

Description

Hi, i have a problem uploading files to the aem and due to this problem i dont know the "real" problem.

Currently the Module cant parse the response it receives, because it is not a JSON content.

I try to upload several files to different directories by using the file "FileSystemUpload" class several times (once for each target directory)

e.g.
first call with files:
- content/dam/US/pdf/subdir/file_1

second call with file:
- content/dam/US/pdf/subdir/sub_sub_dir/file_2
- content/dam/US/pdf/subdir/sub_sub_dir/file_3

third call with file:
- content/dam/US/pdf/file_4

### Expected Behaviour
Upload works fine for each call

### Actual Behaviour
During the upload for the "second call" the module is not able to parse the response, because its not a JSON content.

```
UploadError: Unexpected token '<', "

Content created'
at UploadError.fromError (/builds/n-tier-application/adobe-asset-upload-test/node_modules/@adobe/httptransfer/lib/block/upload-error.js:72:20)
at TransferController.<anonymous> (/builds/n-tier-application/adobe-asset-upload-test/node_modules/@adobe/httptransfer/lib/aem/aemupload.js:53:43)
at TransferController.emit (node:events:514:28)
at TransferController.notifyError (/builds/n-tier-application/adobe-asset-upload-test/node_modules/@adobe/httptransfer/lib/controller/transfercontroller.js:186:14)
at AEMInitiateUpload.execute (/builds/n-tier-application/adobe-asset-upload-test/node_modules/@adobe/httptransfer/lib/functions/aeminitiateupload.js:171:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async executeBatch (/builds/n-tier-application/adobe-asset-upload-test/node_modules/@adobe/httptransfer/lib/generator/mapconcurrent.js:79:22)
at async waitResult (/builds/n-tier-application/adobe-asset-upload-test/node_modules/@adobe/httptransfer/lib/generator/mapconcurrent.js:35:37)
at async MapConcurrent.execute (/builds/n-tier-application/adobe-asset-upload-test/node_modules/@adobe/httptransfer/lib/generator/mapconcurrent.js:[159](https://gitlab.aldidevops.com/n-tier-application/adobe-asset-upload-test/-/jobs/13520219#L159):20)
at async FilterFailedAssets.execute (/builds/n-tier-application/adobe-asset-upload-test/node_modules/@adobe/httptransfer/lib/functions/filterfailedassets.js:30:26) {
code: 'EUNKNOWN',
innerStack: `SyntaxError: Unexpected token '<', "<html>\n` +
`<he"... is not valid JSON while parsing '<html>\n` +
'<head>\n' +
" <title>Content created'\n" +
' at JSON.parse (<anonymous>)\n' +
' at parseJson (/builds/n-tier-application/adobe-asset-upload-test/node_modules/json-parse-better-errors/index.js:7:17)\n' +
' at /builds/n-tier-application/adobe-asset-upload-test/node_modules/node-fetch-npm/src/body.js:96:50\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
' at async Immediate.invoke (/builds/n-tier-application/adobe-asset-upload-test/node_modules/@adobe/httptransfer/lib/retry.js:[171](https://gitlab.aldidevops.com/n-tier-application/adobe-asset-upload-test/-/jobs/13520219#L171):32)',
uploadError: true
}
```

### Reproduce Scenario (including but not limited to)
This is my current used code
```
const options = new FileSystemUploadOptions()
// uploadUrl will be dynamically created - depending on the folder structure
// (e.g. https://author-xxxx.adobeaemcloud.com/content/dam/US/pdf/subdir/sub_sub_dir)
.withUrl(uploadUrl)
.withHttpOptions(
{
headers: {
Authorization: 'Bearer ' + accessToken
}
}
);

const fileUpload = new FileSystemUpload();
// filesToUpload == list of local file paths
await fileUpload.upload(options, filesToUpload
).then(result => {
const {detailedResult = []} = result;
detailedResult.forEach((fileResult) => {
const {result = {}} = fileResult;
const {errors = []} = result;
// ATM we dont need the result object
// console.log(`Result: ${fileResult}`)
if (errors.length === 0) {
console.info(`>>>>> Successfully uploaded files <<<<<`);
} else {
process.exitCode = 1;
console.error(">>>>> Upload failed <<<<<");
errors.forEach((err) => {
console.error(err);
});
}
});
}).catch(err => {
console.error("Unexpected Error during Upload - ", err.message);
console.error(err);
process.exitCode = 1;
});
```
#### Steps to Reproduce

#### Platform and Version

#### Sample Code that illustrates the problem

#### Logs taken while reproducing problem

Contributor guide

Open the contributing guide

Research direction

Reproduce the repeated FileSystemUpload calls against the AEM upload URL, then inspect the AEMInitiateUpload path shown in aeminitiateupload.js and the error conversion in upload-error.js. Compare the HTML response with the expected upload response and determine why the second call receives it; done means the failure is diagnosed and handled with a useful error or the upload succeeds consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.