Questions tagged as ['files']

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/styles/square/private/images/IMG_0371_24.jpg/IMG_0371_24.jpg
The problem is when I display the original image, it works fine. But when I display the image with style, the image is not displaying and in th ...

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
module which would allow uploading files for webform submissions.
When POSTing the file via /webform_rest/{webform_id}/upload/{field_name}
with the necessary Content-Type and Content-Disposition, Cookie a ...
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 randomly and consistently, the response for the files are html
- the login form to be precise. Not all files but some of them and randomly. Sometime it works, sometimes it doesn't. If I logout and login again, it w ...

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 &$form_state, $context) {
if (isset($element['#field_name'] == 'field_file_description') {
// Add process callback to change field description.
$element['#process'][] = 'chg_desc';
}
}
}
func ...
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 as the module adds the site language to the url (ex: www.example.com/**en**) since the website is multilingual.
how can i achieve this? i tried https://www.drupal.org/project/media_entity_file_redirec ...
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.dummy.com/media/redcar_brochure/ then they should be able to view the www.dummy.com/sites/default/files/2021-10/redcar_brochure.pdf file directly in the attached media page. This will avoid clicking the file ...
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 I can't find out what I should do to have a custom font used in the PDF.
The mPDF documentation gives me an example of what I should do to load the custom font. I tried adding this in a custom functi ...
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 private file field from content type are accessible through URL, but as encrypted files aren't accessible through direct URL, I thought of copying the decrypted files from the encrypted folder to the priv ...
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 javascript libraries to show the documentation like swagger website do. Then i copy my yml file in my module directory and in my controller i can load this file.
public function buildApiDocumentation() ...
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/files'. It's a multisite instance and it's public file directory is 'sites/example.com/files'. I have exported the configuration generated with migrate-upgrade --configure-only and can change the so ...

My site was built using Lightning Drupal distribution.
I had my public path as /sites/default/files. I did change the configuration path to /sites/<my_domain>/files in the middle of the project. From then, when I upload an image to a node it's taking the destination as /sites/<my_domain>/files as expected.
Problem:
I've created a view block to display the node titles and images on the home pa ...
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 performance issue once there are a lot of files. To avoid this, I would like to include a timestamp in to the path where to file will be stored, similar to what Drupal does to regular file uploads.
Is there a w ...
I have a question on IMCE File upload. Hope someone might have come across the similar issue.
Installed modules:
We have added a file/image field and chosen following option from Manage form display [admin/structure/types/manage/mycontent-type/form-display] to have Open File Browser option above the specific field.
Allow users ...

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 of allowable extensions in the field definition to include .xlsm
Our xlsm files are code-signed and certified by a Microsoft-approved cert provider.
We can upload the xlsm files no problem, and logged-in users ...
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 seen suggestions of other hooks like file_access and file_access_alter; but none of these exist any more.
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'
defaults:
_title: 'PDF download'
_controller: '\Drupal\my_module\Controller\MyModuleController::downloadPDF'
requirements:
_role: 'authenticated'
MyModuleController
public function downloa ...
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($encodedData['content']);
$data= $this->grabImage($path);
$file = file_save_data($data, null, FileSystemInterface::EXISTS_REPLACE);
$id = $file->id();
I am using file_save_data drupal meth ...
I am trying to create a product with a product image on drupal using API. There was nothing given regarding uploading an image in API so I created a custom module under which i used this code to upload my image to the Drupal:
$data = base64_decode($encodedData['content']);
$file = file_save_data($data, 'public://astha.jpg');
$return['id'] = $file->id();
using this my image get uploaded to the follo ...
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 production environment, one for our staging environment, and one for my development environment. The Drupal configurations are set up to point to their respective s3 bucket based on environment.
There's be ...
I have been breaking my head on this issue for a few days now. Using Drupal 9.2.x, I am building a custom field module for a client that has multiple fields. I isolated the problem by only including a managed file field for now, because the other fields are not causing this issue.
I defined a managed file element in my Widget class, which extends WidgetBase:
public function formElement(FieldItemListIn ...
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 the link to the file like this:
$build['#link'] = Link::fromTextAndUrl(t('Download original file: ' . $file_name), Url::fromUri($url, $options))->toRenderable();
However, the link generated is only acc ...
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 formats: json, xml
Authentication providers: cookie,
but when I try to get a json for a file (by appending ?_format=json
to the url), I just get the file itself back (in other words the page is the same as ...