Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Plupload Form element creates unmanaged files only. We should provide a helper function that will save that files to managed_file table. There would ideally be also a element_value callback that would use this helper function to create managed files and provide their fid's as values.
Comment | File | Size | Author |
---|---|---|---|
#17 | plupload-save-file-managed-2245927-16.patch | 8.65 KB | dvmanjunath |
#15 | plupload-save-file-managed-2245927-15.patch | 15.44 KB | init90 |
#14 | plupload-save-file-managed-2245927-14.patch | 15.72 KB | budalokko |
#13 | plupload-save-file-managed-2245927-13.patch | 15.13 KB | Alex Zhulin |
#12 | plupload-save-file-managed-2245927-12.patch | 15.03 KB | Alex Zhulin |
Comments
Comment #1
dagomar CreditAttribution: dagomar commentedIt seems that the default way drupal handles this is in Drupal\file\Element\ManagedFile::valueCallback.
I'm wondering what the reasoning is to have this done by a helper function or method? Wouldn't it be better if this would be handled in Drupal\plupload\Element\PlUploadFile::valueCallback?
Comment #2
budalokko CreditAttribution: budalokko commentedCorrect me if I am wrong, but all files uploaded with FileManaged element are stored both on disk and file_managed database table.
The PluploadFile element provided by the plupload module does not do any of these on it's own. It's more like the File FAPI element found at Drupal\Core\Render\Element\File which just renders a widget and takes care of files being available on the corresponding submit callback.
The responsibility for doing this kind of things (save on disk and store on database) is for the module calling it and the form's submit callback. At least it was like this in D7.
Actually there is still a "file_copy" method on D8, so this callback method could be based on it.
Task was created long time ago. Does it still make sense to write it?
Comment #3
veronicaSeveryn CreditAttribution: veronicaSeveryn at Inclind Inc commentedI am not sure how to properly document my solution here or on related issues... I will just link all of them together and describe what I did to make things work with Plupload and Plupload Widget to have a solution to uploading a SINGLE file (SINGLE is tested for sure. Have not looked into MULTIPLE uploads).
I needed a Plupload Widget to be available as a Field Formatter on File Upload field. So, I utilized the DEV version of the code provided here: https://www.drupal.org/project/plupload_widget
I have a SINGLE file upload field on a content type. When using these 2 modules together as is, I was having issues with finalizing the upload and getting the file registered within managed table. So, for one of my projects purposes, I came up with a fix that does what I need. It might need to be tweaked or "prettified", but at least it works for me as of this moment with the 2 patches I have: 1 for Plupload and 1 for Plupload Widget.
For the Plupload patch, I did integrate the fix offered in this issue: https://www.drupal.org/node/2645658.
So, what I did to make it work for me:
Comment #4
veronicaSeveryn CreditAttribution: veronicaSeveryn at Inclind Inc commentedMarking for review
Comment #5
RKopacz CreditAttribution: RKopacz as a volunteer commentedAny news on this issue?
Comment #6
Gábor HojtsyComment #7
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedChasing head
Comment #8
khiminrm CreditAttribution: khiminrm at Lemberg Solutions commentedHi!
Solution from #3 doesn't work for me in Drupal 8.4.2.
I use plupload widget for file field in media entity.
After saving file it has path http://mysite.loc/system/temporary?file=o_1c4ftk0m613t61okp8td1ufc16ja.tmp
Any suggestions?
Thanks!
Comment #9
khiminrm CreditAttribution: khiminrm at Lemberg Solutions commentedI was able to upload file after changing public folder permission to 777 recursively.
But I've noticed that filename is not appeared near 'Remove' button and I upload new file, after removing uploaded one. Error occurs:
The website encountered an unexpected error. Please try again later.
Comment #10
khiminrm CreditAttribution: khiminrm at Lemberg Solutions commentedErrors in #9 have disappeared after flushing site's and browser's cache.
Still one bug: file is not removed from folder when it's removed in admin page from media entity or when whole media entity is removed. Cron also doesn't remove such file. How it can be fixed?
Comment #11
khiminrm CreditAttribution: khiminrm at Lemberg Solutions commentedI've found answer for question in #10 about deleting files. It's related to https://www.drupal.org/node/2891902.
Patch from #https://www.drupal.org/project/plupload/issues/2245927#comment-11560277 works for me. Thanks!!!
Comment #12
Alex Zhulin CreditAttribution: Alex Zhulin commentedUsing:
- Drupal 8.5.3;
- Plupload library 2.3.1;
- plupload 1.x-dev with applied patch from #7;
- plupload_widget 1.0 with applied patch from https://www.drupal.org/project/plupload_widget/issues/2697357#comment-11....
Some file uploads fail because the regular expression parsing element ID does not consider the underscores in the hash appended to the ID after AJAX.
Also extra records are created in the file_managed table for the same file with "temporary://..." uri.
Created a patch based on #7 to fix these issues.
Module plupload_widget requires a patch from https://www.drupal.org/project/plupload_widget/issues/2697357#comment-12... (#13).
Comment #13
Alex Zhulin CreditAttribution: Alex Zhulin commentedUpdated patch from #12 to fixed file destination.
Comment #14
budalokko CreditAttribution: budalokko commentedA little part of this patch was commited in #2645658: Wrong regular expressions when processing file input. Attached patch is same as #13 for current dev.
Comment #15
init90I use pluapods as a custom form field. To store the files I used the patch #14. Using this patch I found the problem with multi-file uploads, after uploads in $form_state, we have data only about the first file. The problem was in the following place:
As a result, I simply deleted the problem code snippet, because I did not understand it's purpose. After that, everything works fine. But, I am not sure about the fully correctness of this decision.
Comment #16
budalokko CreditAttribution: budalokko commentedRegarding last comment #2245927-15: Create helper function that will save uploaded files to file_managed table from @pavlo.dovhan, that patch is for compatibility between Plupload and Plupload widget module.
Most straightforward way to achieve what you wanted is do not apply the patch and simply do as in PluploadTestForm::submitForm().
Comment #17
dvmanjunath CreditAttribution: dvmanjunath as a volunteer commentedUpdated patch from #14 to fix deprecated errors and making it compatible with Drupal 9.