cancel
Showing results for 
Search instead for 
Did you mean: 

Issue in creating document using SAP BTP DMS API'S from CAPM nodejs project

divyeaggarwal
Explorer
0 Kudos

I am trying to upload PDF in SAP BTP DMS using CAP Project and i am getting error. No Content Available when displaying the PDF. It is getting uploaded successfully.

I have base 64 for PDF and I am converting it using Buffer var buf = Buffer.from(base64, "base64");

Below is my Code

var buf = Buffer.from(base64, "base64");
        const formData = new FormData();
        // formData.append("objectId", forlderName);
        formData.append("cmisaction", "createDocument");
        formData.append("propertyId[0]", "cmis:name");
        formData.append("propertyValue[0]", fileName);
        formData.append("propertyId[1]", "cmis:objectTypeId");
        formData.append("propertyValue[1]", "cmis:document");
        formData.append("datafile", buf);
        // formData.append("filename", fileName);
        // formData.append("succinct", "true");
        formData.append("_charset", "UTF-8");
        formData.append("includeAllowableActions", "true");

        let headers = formData.getHeaders();
        headers["Authorization"] = "Bearer " + jwtToken;
        // headers["cmis:contentStreamMimeType"] = "application/pdf";

        const config = {
            headers: headers
        }

        axios.post(folderCreateURL, formData, config)
            .then(response => {
                resolve(response.data.properties['cmis:objectId'].value)
            })
            .catch(error => {
                reject(error)
            })

Accepted Solutions (0)

Answers (1)

Answers (1)

nicorunge
Participant
0 Kudos

Hi,

I recently wrote some similar code to upload a file to a cmis system (not BTP DMS). I'm adding the buffer content like this:

form.append('content', file.content, {
contentType: file.mediaType,
filename: file.fileName
})

 You are sure that 'datafile' is correct?

formData.append("datafile", buf);

I also add the Content-Length to the header like this:

const headers = {
                ...form.getHeaders(),
                'Content-Length': form.getLengthSync()
            }

BR,
Nico

divyeaggarwal
Explorer
0 Kudos

HI Nico,

buf is because i am above converting base 64 to buffer to pass to content.

Regards

Divye

nicorunge
Participant
0 Kudos

Hi Divye,

I was talking about the parameter name 'datafile' instead of 'content'. 🙂