cancel
Showing results for 
Search instead for 
Did you mean: 

How to add parameters to UploadSet?

MioYasutake
Active Contributor
0 Kudos

Hi community,

I'm trying to upload files to Document Management Service.

To do so, I need to send some form data together with a file. The screenshot below is the actual form data sent.

With UploadCollection we would do this by the following code.

        onAttachmentsChange: function (oEvent) {
            var oUploadCollection = oEvent.getSource();
            oUploadCollection.addParameter(new UploadCollectionParameter({
                name: "cmisAction",
                value: "createDocument" // create file
            }));

            oUploadCollection.addParameter(new UploadCollectionParameter({
                name: "propertyId[0]",
                value: "cmis:objectTypeId"
            }));

            oUploadCollection.addParameter(new UploadCollectionParameter({
                name: "propertyValue[0]",
                value: "cmis:document"
            }));

            oUploadCollection.addParameter(new UploadCollectionParameter({
                name: "propertyId[1]",
                value: "cmis:name"
            }));

            oUploadCollection.addParameter(new UploadCollectionParameter({
                name: "propertyValue[1]",
                value: oEvent.getParameter("files")[0].name
            }));
        },

Now that UploadCollection is deprecated, I want to implement upload using UploadSet.

However, in UploadSet I cannot find a method equivalent to addParameter() in UploadCollection.

How can I add parameters to UploadSet? Or, should I fall back to UploadCollection for this case?

Best regards,

Mio

You may try with method addHeaderField of sap.m.upload.UploadSet to add fields in the header section of an XHR request

cuong_luc
Explorer
0 Kudos

Hi mioyasutake,

Did you find any solutions? I'm doing the same thing and I couldn't attach any parameters even when I add headerFields and customData, I need to send some key value to backend together with the file.

Best regards,

Cuong Luc

MioYasutake
Active Contributor
0 Kudos

Hi cuong_luc,

Unfortunately, I haven't found a solution. I used UploadCollection instead.

Dipankar
Participant
0 Kudos

I had a similar requirement and had to proceed with UploadCollection !

cuong_luc
Explorer
0 Kudos

Can you guys share how you set the attributes for UploadSet/UploadCollection because it doesn't load the data from the backend automatically for me.

CR_Documents is association between main entity and document entity, even when I try only with DocumentSet, it doesn't send $batch request to the backend to call get_entityset method.

I really appreciate if you could help.

Thanks,

Cuong

MioYasutake
Active Contributor
0 Kudos

Hi cuong_luc,

I think you need "/" before the entityset name like "/CR_Documents".

cuong_luc
Explorer
0 Kudos

Hi Mio Yasutake,

Thanks for your reply, I tried it several times, but it didn't work :(. Does it load data automatically from back-end for you or you have to call read request yourself?

Thanks,

Dinh Cuong Luc

MioYasutake
Active Contributor
0 Kudos

Hi cuong_luc,

You don't need to write code for read request because it is static binding.

Here is an example.


cuong_luc
Explorer
0 Kudos

Hi Mio Yasutake,

thanks for your reply, now my application is able to upload and download the files, but I couldn't find any guidance for implementing delete_stream method in the backend, don't we have to implement that?

Thanks,

Cuong

0 Kudos

Hi Mio Yasutake,

Are you able to set parameters in sap.m.uploadset and upload the document to DMS?

If yes, can you please share the solution?

Thanks,

Saurabh

Accepted Solutions (0)

Answers (1)

Answers (1)

yogananda
Product and Topic Expert
Product and Topic Expert
0 Kudos

mioyasutake

You can add parameters to an UploadSet using the setParameters() method.

// create a new UploadSet object
let uploadSet = new UploadSet();

// define the parameters
let params = {
    maxFileSize: "2MB",
    allowedMimeTypes: ["image/jpeg", "image/png"],
    maxNumberOfFiles: 10
};

// add the parameters to the UploadSet
uploadSet.setParameters(params);
MioYasutake
Active Contributor
0 Kudos

Hi yoganandamuthaiah,

Thanks for your reply.

I couldn't find setParameters() in the document, but is this available?