I am looking for a way to set a custom upload directory for the images uploaded in an album. The most logical way to seems to configure this on the image field used by the photos entity type provided by the module on admin/structure/photos/fields/photos_image.photos_image.field_image. By default this is set at photos/image, but all images are uploaded to the directory photos in the file system, is this perhaps hardcoded or overridden somewhere?
I am aware that a similar question was asked in https://www.drupal.org/project/photos/issues/2516644, but that does not really help me.
The ultimate goal is for images to be uploaded to a directory that is the nid of the album it is in, so photos/[nid]. I tried to use a token in the field on admin/structure/photos/fields/photos_image.photos_image.field_image, but without success (every image is always uploaded to photos).
In the documentation on https://www.drupal.org/docs/contributed-modules/album-photos/photos-8x-4x I noted that there used to be a configuration option for the upload path in the admin section of the module, does this no longer apply for the 6.0.x version? It say the following:
Path:
This defines a custom path within your files directory to store the original images upon upload.
Can anyone help me with this? Perhaps I am simply not looking in the right place, any help would be greatly appreciated :-)
Cheers!
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | photos-custom-upload-directory-3224513-6.patch | 9.28 KB | nathaniel |
| #6 | photos-custom-upload-directory-3224513-6-TEST-ONLY-FAIL.patch | 2.45 KB | nathaniel |
| #3 | photos-custom-upload-directory-3224513-3.patch | 6.83 KB | nathaniel |
Comments
Comment #2
nathaniel commentedAre you using plupload? Looks like there is a bug when using plupload. The entity form appears to be working as expected.
There is a bit about what you want to do at the bottom of this guide:
https://www.drupal.org/docs/contributed-modules/album-photos/8x-4x-to-6x...
File (Field) Paths looks like the best option.
https://www.drupal.org/project/filefield_paths
This would be the album nid when using filefield_paths: [photos_image:album_id:target_id].
Comment #3
nathaniel commentedWorking on a patch that will add support for the image field path settings and filefield_paths/token settings. Looks like the issue exists for zip directories, directory import, plupload and possibly the classic form. Still need to test all.
Comment #4
frontmobeHi Nathaniel,
Thanks for your reply!
I am using Plupload, I should haven mentioned that. I tested with https://www.drupal.org/project/filefield_paths and moving the original images to an album-named directory based on the [photos_image:album_id:target_id] token works beautifully.
Using the filefield_paths module introduces a new challenge though, images uploaded with plupload seem to no longer hit the resolution restrictions causing the originals to be very large. I had the max resolution set at admin/config/media/photos and tried to also set the same resolution at admin/structure/photos/fields/photos_image.photos_image.field_image, without success. I suppose this because filefield_paths moves the files before any resizing is applied...
I also tried the patch you provided https://www.drupal.org/files/issues/2021-07-20/photos-custom-upload-dire..., after applying this gave the following error:
TypeError: Argument 12 passed to Drupal\photos\PhotosUpload::__construct() must be an instance of Drupal\Core\Utility\Token, instance of Drupal\Core\Transliteration\PhpTransliteration given
Due to this error I was not able to test the patch, I would absolutely love to help testing it though.
Do you see any way I could move photos uploaded with plupload to their own directory while still having them resized according to the maximum dimensions set?
Thanks for all the great work Nate, really appreciate it a lot!
Comment #5
nathaniel commentedThanks for your testing and feedback it's very helpful! Clearing cache should fix the error from the patch. I'll try to test more today and see what is going on with the resolution.
Comment #6
nathaniel commentedWorking on some automated tests for this.
Comment #8
frontmobeI tested the patch in #6 https://www.drupal.org/files/issues/2021-07-21/photos-custom-upload-dire... and can confirm it solves the issue of resizing to the correct resolution (after clearing cache ;-) ).
To summarize:
- I installed filefield_paths module and use [photos_image:album_id:target_id] as the token for the directory path. I also tested with a token in the filename, works fine, so the integration with filefield_path works as expected.
- Uploading with the Plupload library, after the images are uploaded to the filesystem and moved to the correct directory, they are resized according to the resolution settings on admin/structure/photos/fields/photos_image.photos_image.field_image.
- Thumbnails (any image styles) were not generated earlier, that now works fine as well.
So uploading images to tokenized (sub)directories by using the filefield_paths module wokrs really well, including resizing...
Great patch, many thanks Nathaniel!!
Comment #10
nathaniel commentedThanks for the testing and thorough review! Added to dev. I plan to test some of the other upload options manually then will add a new release.