How do I change the image name while uploading through a file uploading field? In drupal 8 whenever I add an image to a file field, it automatically uploads the image file to my S3 bucket. I need to change the image name before uploading because I need to list my image names with a specific pattern. I searched the internet but couldn't find a hook for that auto image uploading.

1 Answer 1


If you're uploading a file I'm assuming it's within a form, right? You could add a submit handler function using form_alter() (or override the submitForm() method) and change the file's name using the $form_state object's setValue() and getValue() methods I'm sure.

  • Unfortunately I can't do that because that file upload field is in a content type and as soon as I added the file to the file uploading field it gets uploaded to the S3 bucket. So practically I can't get it from submitForm(). Commented Apr 11, 2018 at 10:43
  • Does it immediately send the file to S3 as soon as the user uploads? Commented Apr 11, 2018 at 10:58
  • Yes that is how the Drupal 8 file uploader works. Commented Apr 11, 2018 at 11:13
  • I'm not sure I understand. Did you build your D8 site from a pre-built setup on S3 or do you develop on a local machine and then deploy? I ask because I can't understand how it would immediately upload the file to S3 before you get the chance to modify it. Do you have an AWS/S3 module installed that does that for you? Commented Apr 11, 2018 at 11:30
  • It doesn't matter whether you use S3 or local file storage it always upload the files automatically to the server when selecting. You can create a content type and add a file field. You will see yourself. Commented Apr 11, 2018 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.