Questions tagged [files]
Use it to generally reference to those files used on websites which could be video, images, pdfs, etc.
2,469
questions
1
vote
1
answer
76
views
Key based access control for private files
I'm building a site that provides paid video content, for embedding in customer's own sites. I'm successfully controlling access to the nodes that contain the video content based on purchasable user ...
1
vote
1
answer
200
views
Compress file with ArchiveInterface without file paths
I'm trying to create an archive of log files to be downloadable in a form making a custom module in Drupal 9.
In the form, the user can change the format of the archive, as per image:
Here below my ...
0
votes
1
answer
24
views
Actual file permisions
With Drupal 8/9 I want to:
Have a private file folder
Upload files to it (ideally by whatever method but media type will do)
Allow only authenticated users (ideally set by role) to view the file (...
0
votes
1
answer
137
views
Writing to the temporary directory randomly stops working [closed]
In one of the websites on production, when Drupal writes on the temporary directory, it randomly stops working with the following error, even though the permissions are set correctly, and there is ...
0
votes
0
answers
133
views
Migration does not pick up files
Please forgive me for not going the canonical path with either Drush or Composer. I tried, but could not find documentation to get me started. I'm coming from a Debian installation of Drupal 7 that ...
2
votes
0
answers
404
views
I cannot access PDF files uploaded in the private directory
PDF files uploaded to the private directory cannot be viewed and returns a 404 error.
This also happens to the user with the Administrator role.
Other file types can be viewed with no issue.
This ...
0
votes
2
answers
146
views
Files with 644 permissions and owner apache:apache are still failing Security Review module
I am using Drupal 7 and just installed Security Review. According to this page, the files should be 644. I tried that but I am still failing Security Review (I'm getting hundreds of files under the ...
0
votes
1
answer
45
views
Private File Permissions Not Working for a Single file - Can't Identify where to find error
I have the following set up:
Private file field configured on content type
Access control configured with referenced user having permission to view file
If user is referenced on the node, they can ...
1
vote
2
answers
227
views
Override the default private file access
In the site I am developing, the private files directory is outside the document root.
I have a content type (Chapter) with a file field that stores its files in the private files directory. When a ...
0
votes
1
answer
902
views
How do i save a base64 decoded image to file_managed?
I'm trying to save my image to Drupal's file_managed table. However, my image is coming from base64 decode:
$filename = "sign-".$user->id(); // returns "sign-1234"
$image_raw =...
1
vote
1
answer
899
views
How can I overwrite existing file and keep same filename when uploading new
I have content type 'Document' and added the 'Upload document' field with type 'File'
I want to replace file and update the node. I'm using below code
function custom_file_upload_form_alter(&$form,...
1
vote
0
answers
103
views
Permission denied on some private files, even though access is permitted
Drupal 9.3
We have a site that allows private file uploads. We get intermittent files that cannot be viewed/downloaded, even with the "User 1" account.
There is no difference between a ...
0
votes
0
answers
51
views
Document File Field Ajax Error
I am having trouble with file uploads for anonymous users. I get a non-descript ajax error. It works fine when signed in as an admin user. Any ideas on how to troubleshoot the problem? I've made ...
0
votes
0
answers
583
views
How do you add a PDF attachment to a page?
Complete Drupal Newbie here. I have created a basic Drupal 9 site so as to teach myself Drupal. I have added some Basic pages, and put them onto the menu. I can edit the text in each page just fine,...
0
votes
1
answer
138
views
Link to images in form view creates wrong url
I noticed this after drupal 9 update, but I've tried to find the exact moment when it was broken and I couldn't find it. I use S3 and cloudfront for images so maybe the problem is related with that ...
0
votes
0
answers
135
views
Image compression problem
I keep on running into an issue with image compression on Drupal.
I have a set of good quality, clear images, that I'm resizing down to 100px by 100px in CSS.
When I resize, the quality worsens and ...
1
vote
1
answer
344
views
How to migrate files from outside Drupal, with files already where they need to be, creating file entities
I'm doing a migration from a non-Drupal site--so far, for test purposes.
I have all the data in CSV files.
Since I'm brand new to migrating into Drupal 9 from outside Drupal, I'm learning this in ...
1
vote
0
answers
475
views
Restrict a Media field to allow selecting only a certain file extension in an existing Media Type
Is there a way to restrict a Media field using an existing Media Type (File) in a Content Type to permit only a certain file extension in that instance?
In particular, I need a subset of the permitted ...
0
votes
0
answers
267
views
How to set an encrypted file field's value programmatically
I'm trying to set an encrypted file field's value programmatically. I'm using Encrypted Files module. I have successfully configured a file field, and it works for the contents created using the node ...
1
vote
1
answer
231
views
Is it possible to allow anonymous users to view a temporary managed file via hook_file_download()?
I am creating a live image preview system for customizable products that needs to send a user's temporary file to a remote server.
I have a token-based system to protect the file but the problem seems ...
0
votes
0
answers
146
views
Why are the images referenced using a relative path instead of an absolute path?
I have installed my Drupal site on my localhost under a path like /websites/mysite/drupal. Most files get loaded correctly, such as those at /websites/mysite/drupal/sites/default/files.
For some ...
2
votes
1
answer
546
views
get the file URI of an ImageItem
How can I get the file URI of a Drupal\image\Plugin\Field\FieldType\ImageItem instance?
I get the field value with $node_entity->get('field_image')[0] but I don't know how to get the file URI.
1
vote
1
answer
147
views
Reference private file?
I'm making migration plugin which I'm using in first migration and it is creating private file like this:
if ($final_destination) {
// Create a file entity.
$file = File::create([
'uri' => $...
0
votes
1
answer
192
views
Creating file from s3fs (S3 bucket) breaks migration
I have s3fs module installed and configured, so when I upload some file it goes to S3 bucket.
Then I'm making processing plugin which should copy file from another S3 bucket to Drupal's bucket and ...
0
votes
1
answer
63
views
How to make the private image accessible with image style?
I have a private image with this URL.
http://mystite.com/system/files/images/IMG_0371_24.jpg/IMG_0371_24.jpg
An image style is created for the above image on location
http://mysite.com/system/files/...
0
votes
1
answer
445
views
Unable to upload files through RESTful services
I am trying to upload pdf files to webform submission using REST API.
Since the Core File Upload functionality did not seem applicable for webform submission, I applied the patch from webform_rest ...
0
votes
0
answers
91
views
Getting 403 randomly on files
I have a react-native app that authenticates with Drupal via oAuth2 (simple_oauth, openidconnect) and do not use cookies. I use my access token for all rest calls, images and other files. Very ...
0
votes
1
answer
95
views
How to edit file 'description' label and help text
I want to edit the file upload description label and the help sentence underneath it:
I tried the below code:
function mymodule_field_widget_form_alter(&$element, FormStateInterface &$...
0
votes
2
answers
169
views
redirect an old url that no longer exists related to a file to a new one
I have 2 urls:
www.example.com/somefile.pdf
www.example.com/somefileNew.pdf
the first one no longer exists, i want to redirect this url to the new one. I tried to use the redirect module to no avail ...
0
votes
0
answers
89
views
How can we directly display/download attached document on Media path
I am trying to directly display/download the attached file when the Media link is reached. Main reason behind this is to avoid providing file path directly.
For example: if a user is visiting www....
2
votes
1
answer
1k
views
Add custom font to mpdf while using PDF using mPDF module
I made a custom module to create a PDF from a views page. This module depends on PDF using mPDF. I'm now trying to add a custom Google font. This should be the default font when generating a pdf. But ...
0
votes
1
answer
68
views
How can the custom files copied by code to the private directory be accessible through URL for authenticated users?
In my project, I am using headless Drupal with .Net on the front end.
I have to use private and encrypted file systems for the project requirements. The files which I am uploading through Drupal ...
0
votes
2
answers
256
views
How can i render a file using a formatter programmatically in a controller?
I'm trying to create a controller to render a swagger documentation using the module swagger_ui_formatter that provide a formatter to the file field that render swagger files (yml, yaml, json) using ...
1
vote
0
answers
211
views
Files migration from local dev site
I'm migrating from Drupal 7 to Drupal 9 and am having an issue with my source files getting found with the upgrade_d7_file migration. My public files directory for my source site is not 'sites/default/...
0
votes
1
answer
210
views
Ckeditor inline images path
I am running a Drupal 9 site and I expect my users to upload a lot of files with the ckeditor functionality. All of those files will be
stored in a single folder.
I heard that this will cause ...
2
votes
0
answers
137
views
S3FS IMCE File upload issue for old files in Upgraded site
I have a question on IMCE File upload. Hope someone might have come across the similar issue.
Installed modules:
https://www.drupal.org/project/s3fs
https://www.drupal.org/project/imce
We have added ...
-1
votes
1
answer
61
views
Downloading xlsm is disabled for anonymous user: What function is responsible for this access control?
We have a D7.8 site with Panopoly 7.x-1.81. No access control modules.
A standard filefield is used for uploads and functions perfectly for the usual set of mime types.
We recently extended the list ...
0
votes
0
answers
347
views
How to programmatically grant access to private files?
I was working under the idea that i could use hook_file_download to grant access to private files; but it seems that this hook can only be used to restrict access to files, not to grant access.
I have ...
1
vote
1
answer
201
views
How can I delete a file served by a custom controller after it has been downloaded?
Starting from How do I create a file download URL?
I've build a custom controller that allows users to download a PDF file.
my_module.routing.yml
my_module.pdf_link:
path: '/my-module/pdf/download'
...
0
votes
1
answer
275
views
How do you set the file extension while uploading images through file_save_data?
I am trying to create a product with a product image on drupal using API. I have created a custom module for the same under which following code to upload my image to the Drupal:
$path = base64_decode(...
1
vote
0
answers
69
views
How are compiled CSS and JavaScript files handled with S3?
I have my Drupal site set up to upload public files into the S3 bucket but am having some strange behavior with different environments and different s3 buckets. I have 3 s3 buckets: one for our ...
0
votes
0
answers
204
views
Is it possible to generate a link to a private file that can be shared with an anonymous user to download the file?
In Drupal 8 we need to generate a link to a private file that can be shared with an anonymous user to access.
In our function we have the file object for the private file and are currently generating ...
0
votes
1
answer
27
views
Front and backend public files not found [closed]
I'm trying to display some image in my front and my backend, a simple image, not a media, but I'm always receiving a 404.
For example, I'm trying to display the icon from my paragraph, to i'm ...
1
vote
2
answers
115
views
?_format=json does not produce JSON for files, REST
I am using Drupal 9.3 with REST UI, RESTful Web Services, and Serialization enabled.
For the REST UI, I have the following configuration for files:
Methods:
GET, POST, DELETE, PATCH
Accepted request ...
0
votes
0
answers
248
views
Why can't admin access private file?
I have a file field as part of a Paragraph. The Paragraph is attached to a node bundle. Each paragraph can hold a single file.
I have added the same file to the node (each in its own paragraph) ...
0
votes
1
answer
181
views
Download Single Webform Submission CSV
I would like to download the webform submissions one by one.
Currently the core of Webform owns to download all submission data to a CSV.
Webform -> Result -> Download
How to download one ...
0
votes
0
answers
137
views
How can I change the "sites/default" into "web/sites/subsite" on the new location?
I have moved the content (files and database) of my "traditional" site (no composer, single site, using sites/default/files folder ) to a subsite on a multi-site that is created using ...
1
vote
1
answer
394
views
How can I have the file upload destination private by default?
Currently Webform file component uses public files as default upload destination. This is probably because private files path is not always available if not configured in Drupal settings correctly.
...
0
votes
0
answers
568
views
How to programmatically update a file uri in a node
I'm programmatically moving a pdf file and then trying to update the uri in the node. Here's my code:
$node = \Drupal\node\Entity\Node::load($nid);
$entity = $node->field_pdf->entity;
if ($...
0
votes
1
answer
343
views
How to send dynamic content as an attachment file in email?
Normally we send files as attachments in the email if they are stored in the file system.
$file->uri = 'sites/default/files/file_name.pdf'; // File path
$file->filename = 'file_name.pdf'; //File ...