Immediate_mode break query parameter 'cabinets' for sources/../actions/document_upload/execute/

I try to upload a file from a source directly inside a given cabinet.

For this purpose i use the /sources/<sourceID>/actions/document_upload/execute
and add the query parameter cabinets with the cabinet id

curl --location 'localhost:80/api/v4/sources/2/actions/document_upload/execute/?cabinets=3' \
--data '{
  "arguments" :{
    "encoded_filename":"MTAwYmY5MmItODA4Yi00ODhhLWI4Y2UtYzhkZDNhNWU3Nzc3LmpwZw%3D%3D",
    "document_type_id":3,
    "label": "my Picture",
    "description" : "a description",
  }

I saw the addition of immediate_mode and though it would be a fine addition to my application as it prevents polling Mayan for the id.

So I added "immediate_mode" : true in the body as explained in https://forum.mayan-edms.com/t/sources-api-immediate-mode/1036

curl --location 'localhost:80/api/v4/sources/2/actions/document_upload/execute/?cabinets=3' \
--data '{
  "arguments" :{
    "encoded_filename":"MTAwYmY5MmItODA4Yi00ODhhLWI4Y2UtYzhkZDNhNWU3Nzc3LmpwZw%3D%3D",
    "document_type_id":3,
    "label": "my Picture",
    "description" : "a description",
    "immediate_mode" : true
  }

I see the response with the new file id, which is great

But now my document is uploaded at the root instead of inside cabinet 3 as specified by the query parameter.

1 Like

There is no support to upload documents directly to cabinets. This has come up before but not accepted because it reinforces the file manager paradigm which is an anti-pattern in Mayan.

Do you have custom code to implement this?

If so, then it could be that your custom code needs to be updated to understand the changes in the API response when using immediate mode.

1 Like

I have 50K documents to upload to different cabinets.

So i guess i will have to make some custom code to move them around once the upload is done because from my understanding the ?cabinet is working now but could disappear any time soon.

50K upload requests, followed by 50K move requests. Nice.

I though about using the batch request API to have only one call for upload+move into cabinet.
I put it here as a clue for people facing the same issue.

curl --location 'localhost:80/api/v4/batch_requests/' \
...
--data '{
  "requests": [
    {
      "body": {
        "arguments": "{\"encoded_filename\": \"MTAwYmY5MmItODA4Yi00ODhhLWI4Y2UtYzhkZDNhNWU3Nzc3LmpwZw%3D%3D\",\"document_type_id\": 3,\"immediate_mode\": true }"
      },
      "method": "POST",
      "name": "document_up",
      "url": "/api/v4/sources/2/actions/document_upload/execute/"
    },
    {
      "body": {
        "document": "{{document_up.data.id}}"
      },
      "method": "POST",
      "name": "document_move",
      "url": "/api/v4/cabinets/8/documents/add/"
    }
  ]
}'

I was wondering the same but @roberto.rosario makes it clear there is no such function

There is no support to upload documents directly to cabinets. This has come up before but not accepted because it reinforces the file manager paradigm which is an anti-pattern in Mayan.

If there is no such ?cabinet function, how did you make it work the first time?

1 Like

50K? Looks like a small business install. Get a support plan, don’t cheap out. Support awesome open source like Mayan.