Problem/Motivation
If you import data using:
$file_data = file_get_contents($url);
$file_repository = \Drupal::service('file.repository');
$file = $file_repository
->writeData($file_data,
"public:/{$urlPath}",
FileSystemInterface::EXISTS_REPLACE);
}
You will get the following error on the writeData method call:
Error: Call to a member function isEmpty() on null in /app/docroot/modules/contrib/filefield_paths/filefield_paths.module on line 364 #0 [internal function]: filefield_paths_file_presave(Object(Drupal\file\Entity\File))
Steps to reproduce
Use the above code to try to import a file.
Proposed resolution
The presave function should handle cases where the originname parameter does not exist.
Remaining tasks
Create a patch
User interface changes
None
API changes
None
Data model changes
None
Comments
Comment #2
cgmonroe commentedPatch to fix this problem
Comment #4
cgmonroe commentedHmm, not sure why the token test failed. Trying a different variation that just skips setting the name if the originame parameter does not exist.
Comment #5
megadesk3000 commentedHi togethter
I had the same error when creating a new media image via the backend ui on /media/add/image, after i installed filefield_paths module.
For me it was the case, that $file->filename was not present and therefore the same error came up.
I adjusted the patch slighty and now it works in my case.
Added a patch and an interdiff.
Comment #7
tim@lammar.be commentedRework for version: 1.0.0-beta8
Comment #8
pwolanin commentedWe suddenly started getting this error - trying to track down why, maybe something wrong will file system permissions. It solved the issue enough to get things working and is clearly a pretty safe change
Comment #9
pwolanin commentedComment #11
pwolanin commentedI made an issue fork and included patch #7
Comment #12
klemendev commentedI can also confirm this. I will try the patch later
Comment #13
volegerFixed, thanks