RemotePostWebformHandler::getRequestData appends uploaded file name, uri, and base64 data to data, but this does not seem to work for elements allowing upload of more than one file.

Comments

bonus created an issue. See original summary.

gg4’s picture

Issue summary: View changes
jrockowitz’s picture

StatusFileSize
new4.59 KB

The attached webform replicates this issue.

jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new2.18 KB

The attached patch adds support for multiple files but raises the question, How should multiple files be structured?

Below is how the patch is sending multiple files.

form_params:
  files:
    - 3
  files__0__name: files.mp3
  files__0__uri: 'private://webform/issue_2988239/71/files.mp3'
  files__0__mime: audio/mpeg
  files__0__data: SUQzBAAAAAAAF1RTU0UAAAANAAADTGF2ZjUyLjY2LjAA/

I am open to suggestions.

Here are the options that I can think of right now...

  • Include the delta like above. (ie ELEMENT_KEY__DELTA__PROPERTY)
  • Include the file id. (ie ELEMENT_KEY__FID__PROPERTY)
  • Send array of values for each property (file__name, file__uri, file__mime, and file__data). This would be similar to how preg_match() works.
  • Send array of files in files_data. (see below). The problem here is single files and multiple files are going to work differently.
form_params:
  files:
    - 3
  files_data:
    - name: files.mp3
       uri: 'private://webform/issue_2988239/71/files.mp3'
       mime: audio/mpeg
       data: SUQzBAAAAAAAF1RTU0UAAAANAAADTGF2ZjUyLjY2LjAA/
  • Finally, we could update the file element to include the meta data. This is not backward compatible and breaks existing remote post handling but this is how I would expect files to be sent to remote server.
form_params:
  single_file:
     fid: 71
     name: files.mp3
     uri: 'private://webform/issue_2988239/71/files.mp3'
     mime: audio/mpeg
     data: SUQzBAAAAAAAF1RTU0UAAAANAAADTGF2ZjUyLjY2LjAA/
  multiple_files:
    - fid: 71
       name: files.mp3
       uri: 'private://webform/issue_2988239/71/files.mp3'
       mime: audio/mpeg
       data: SUQzBAAAAAAAF1RTU0UAAAANAAADTGF2ZjUyLjY2LjAA/
gg4’s picture

Let me think about this for a sec, but what do you think about adding the uuid to the data well?

jrockowitz’s picture

I am open to anything that is useful. You are making me feel the entity references should be including uuids and labels.

jrockowitz’s picture

I think the mistake was appending the file data to the form params which should just be the raw submission data.
Files and entities should be included as meta data via '_files' and '_entities' properties.

form_params:
   element_key: raw_data 
   files:
     - 71
     - 72
   nodes:
     - 71
     - 72
   ...
  _files:
    71:
      fid: 71
      name: files.mp3
      uri: 'private://webform/issue_2988239/71/files.mp3'
      mime: audio/mpeg
      data: SUQzBAAAAAAAF1RTU0UAAAANAAADTGF2ZjUyLjY2LjAA/
      uuid: 854f2683-59a1-437d-b2f1-8b36b2ee672a
    72:
      fid: 72
      name: files.mp3
      uri: 'private://webform/issue_2988239/72/files.mp3'
      mime: audio/mpeg
      data: SUQzBAAAAAAAF1RTU0UAAAANAAADTGF2ZjUyLjY2LjAA/
      uuid: a96c8eed-3988-4dcb-8425-f4665f8c1d3f
  _entities:
    element_key
      71:
        entity_type: node
        entity_id: 71
        label: 'Node label'
        url: 'http://site.com/node/71'
        uuid: 661aa40c-f6a0-43b9-b162-ae06ab2187f2
      72:
        entity_type: node
        entity_id: 72
        label: 'Node label'
        url: 'http://site.com/node/72'
        uuid: 798256f0-7f17-47f0-83df-276cbfc9a85e
    other_element_key
      71:
        entity_type: node
        entity_id: 71
        label: 'Node label'
        url: 'http://site.com/node/71'
        uuid: 0be4baa2-78a4-47bc-93a2-a152f21e841a
      72:
        entity_type: node
        entity_id: 72
        label: 'Node label'
        url: 'http://site.com/node/72'
        uuid: 9cffd6d2-7f90-403e-9348-a87925523ac4

We could use this approach and leave the old behavior ASI-IS or remove it via the first stable release of webform 8.5 or wait until webform 8.6.

jrockowitz’s picture

StatusFileSize
new4.93 KB

I think the best approach is to prefix the file element's meta data with an underscore.

The attached patch generates the below post (from /webform/test_handler_remote_post_file/test) while preserving the old 'file__*' data.

form_params:
  single_file: 1
  multiple_files:
    - 2
  _single_file:
    name: file.txt
    uri: 'private://webform/test_handler_remote_post_file/8/file.txt'
    mime: text/plain
    uuid: 62438366-05b5-4654-aaf8-3d95658d3b85
    data: dGhpcyBpcyBhIHNhbXBsZSB0eHQgZmlsZQppdCBoYXMgdHdvIGxpbmVzCg==
  single_file__name: file.txt
  single_file__uri: 'private://webform/test_handler_remote_post_file/8/file.txt'
  single_file__mime: text/plain
  single_file__uuid: 62438366-05b5-4654-aaf8-3d95658d3b85
  single_file__data: dGhpcyBpcyBhIHNhbXBsZSB0eHQgZmlsZQppdCBoYXMgdHdvIGxpbmVzCg==
  _multiple_files:
    -
      name: files.txt
      uri: 'private://webform/test_handler_remote_post_file/8/files.txt'
      mime: text/plain
      uuid: f22c39e0-a3d0-4135-b4a5-faa1d3a48321
      data: dGhpcyBpcyBhIHNhbXBsZSB0eHQgZmlsZQppdCBoYXMgdHdvIGxpbmVzCg==

Status: Needs review » Needs work

The last submitted patch, 8: 2988239-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jrockowitz’s picture

Status: Needs work » Needs review
StatusFileSize
new4.94 KB
gg4’s picture

I think I follow, but do you have a quick example of what this will look like if there are multiple elements allowing a combination of single and multiple files?

jrockowitz’s picture

I updated https://www.drupal.org/project/webform/issues/2988239#comment-12707154 to use more specific element keys (single_file and multiple_files).

You might need to test the patch via your specific webform.

gg4’s picture

I think your updated comment makes this much more clear now. Thanks.

jrockowitz’s picture

I think the fids need to be included in _single_file and _multiple_files. This would allow developers to process only the _{element_key} fields.

jrockowitz’s picture

StatusFileSize
new5.14 KB
new1.99 KB

The attached patches adds the file id to remote post data.

gg4’s picture

+1 for that change.

jrockowitz’s picture

Status: Needs review » Reviewed & tested by the community

Marking this RTBC and I will commit this change later this week.

gg4’s picture

+1 to RTBC as well.

  • jrockowitz committed 28edbb2 on 8.x-5.x
    Issue #2988239 by jrockowitz: Support elements allowing multiple files...
jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.