How should I link (public) files to nodes? I have many resources (mainly PDFs) that need to be imported to my site.  Previously the files would manually be placed in sites/default/files/mydir and linked to the node like this:

&lt;a href="/sites/default/files/mydir/mypdf.pdf"&gt;Read More&lt;/a&gt;


This does work, but I am guessing there are probably strong advantages to actually using the content system - perhaps being able to better organize/track/update files.

How do I place files inside of nodes so the file still appears inline with the rest of the content, while actually being tracked by Drupal?
UPDATE: I missed the 8 tag

Drupal 8.x

UPDATE 2:

So this got trickier. The only way I was able to accomplish it was using these steps:


Add a field to the node, I called mine "Media"
Instead of selecting "File" from the dropdown list, I selected "Other" under reference, and "File" on the next page, this creates an entity reference field rather than a file field.
Add a file through file/add
In your node, start typing the filename of the file you've added
In the body field, enter this token: [node:field_media-formatted:0:entity_reference_entity_view:default]


The token inserts the rendered entity for the reference field into your content, you can edit how it looks (for images e.g.) through the display settings for file types (May require the File Entity module), so you can display a link rather than a rendered file.

Someone pointed out in a thread I saw a couple of months ago: 


  Drupal 8 is stable with exactly 0 contributed modules installed


That said, moving to Drupal 8 with requirements that fall outside of the scope of core may be premature for someone who isn't prepared to develop their own solutions yet, and this particular solution may change since parts of it rely on contributed modules.



Hopefully this will be an appropriate answer in the future

Very similar to how it would be handled in Drupal 7, but because of module availability there are some tweaks. The modules you would need are Token, Token Filter, and File Entity Browser.

The steps are the same as below essentially, but I think the token may use the underscore instead of a dash: [node:field_files:0:url].

Also, once the Token module is installed you can see a list of tokens at admin/help/token.

Drupal 7.x

There are several mechanisms available to achieve this. If you are using a wysiwyg editor (such as CKEditor), they sometimes have plugins available to allow you to add files directly into the content, but based on what you've stated you need, I think possibly the Media, Token, and Token Insert modules would be a good place to start.

The media module provides a file browser and upload mechanism that works with the core Drupal file system, making it possible to reuse files easily in different pieces of content.

The Token module extends Drupal's core token mechanism, and the Token Insert module allows you to use tokens in text fields.

The basic steps would go something like this:


Install all 3 modules, make sure you have the core File module enabled.
Go to the "Manage Fields" page for the content type you plan to use these files in and add a "files" field.
Add the files that would be used in your article to the files field, either through uploading or using the file browser.
Reference the files by index in a token in the text field, a list of available tokens are available here.


This is untested so may require some tweaking, but if the machine name for your file field is "field_files", the link in the text area would probably look something like this:

&lt;a href="[node:field-files:0:file:url]"&gt;Read More&lt;/a&gt;

That would print the link for the first file that is attached to the node.

There will, of course, be some configuration pages you will have to go through for the media module and field settings, but it's hard to give you any direction on those since they are all very much dependent on your particular installation.