How do I change where the media files get uploaded to? Currently all the files get uploaded to the top level of my files directory. Ideally I'd like to create a new folder for each media type. Sorry if this has been covered before.

Comments

tomgf’s picture

I am having the same situation.

It could be good to have the possibility of pointing where these files should be going, like you do with other fields (at least when using the image widget).

Any suggestions?

Zachmo’s picture

subscribing

guypaddock’s picture

Subscribing

kaptinfly’s picture

So I've gotten around this problem by adding an image field to the content type and uploading all my images first. They go into the specified directory created in the field settings. Then I can go to the media library and pick a recently added image. You have to completely ignore the Upload button in the media module. This might get confusing to some people who have to add content.

tomgf’s picture

@kaptinfly: you are right. This is a workaround but it will confuse some people… And from an usability perspective, it's not very good to have this extra step…

What I am thinking of is to create a module that will organize the files afterwards. It could easily check the table file_managed and move all the files having an uri value like public://FILENAME.EXT to subdirectories, i.e. using the timestamp value from the same table.

This could run on cron and move the files to this kind of structure:

  • 2011
    • 01
    • 02
  • 2010
    • 01
    • 02

In this case, this module won't interfere at all with the Media module and it could be removed afterwards when Media has a better way of organizing uploaded files…

What do you think about this idea?

dwalker51’s picture

Sounds great!!! I was thinking about the same....not sure how to do it, I haven't really gotten into drupal modules quite yet.

What I did find out is that yes...if you move the files around and rename them , create subdirectories, changing the link in file_managed will make them appear correctly when viewing the images, such as when using the media module.

for example here is a select from the table file_managed

| 119 |   1 | Clean mirror.jpg | public://field/image/Clean mirror.jpg | image/jpeg |  1743792 | 1 | 1301931922 | image   |
| 121 |   1 | lsst_first_blast.JPG| public://field/image/lsst_first_blast.JPG | image/jpeg |  2010687 | 1 | 1302279407 | image   |
| 126 |   1 | crap.png | public://gallery2/crap.png | image/png   | 79633   | 1 | 1302289512 | image   |

In the last line I had created in the public directory a subdirectory called gallery
I moved the directory gallery to gallery2 (renamed)...and then changed in this table the uri field from gallery to gallery2.

That solves viewing with the media module

However all nodes that have been created with the original file link will still show a missing file.

I found that by looking in the filed_data_body table, content was saved there.
Here is the table

describe field_data_body;
+--------------+------------------+------+-----+---------+-------+
| Field        | Type             | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+-------+
| entity_type  | varchar(128)     | NO   | PRI |         |       |
| bundle       | varchar(128)     | NO   | MUL |         |       |
| deleted      | tinyint(4)       | NO   | PRI | 0       |       |
| entity_id    | int(10) unsigned | NO   | PRI | NULL    |       |
| revision_id  | int(10) unsigned | YES  | MUL | NULL    |       |
| language     | varchar(32)      | NO   | PRI |         |       |
| delta        | int(10) unsigned | NO   | PRI | NULL    |       |
| body_value   | longtext         | YES  |     | NULL    |       |
| body_summary | longtext         | YES  |     | NULL    |       |
| body_format  | varchar(255)     | YES  | MUL | NULL    |       |
+--------------+------------------+------+-----+---------+-------+

I found a test page i had created with the original file in gallery (entity_id was 116). Its link was still wrong so I did an sql update and then the image in gallery2 appeared on the test page

update field_data_body set  body_value = ' <p>
<img alt="" src="/noao/sites/default/files/gallery2/crap.png" style="width: 300px; height: 229px; " /></p>
<div id="myEventWatcherDiv" style="display:none;">
&nbsp;</div>
' where entity_id = 116;

So it seems that you have to modify at least these two tables, questions I have are:

Are these the only tables that need to be modified?
Sounds like a script that goes through both tables looking for the respective file link shouldn't be too difficult?

At this point I am tempted to just wait and maybe make a file structure, have my users use that, and then just hope that some sort of file management module comes out or that media finally allows me to update and modify folders/filenames, most of the modules that might do this like webfm are a while away from version 7. http://drupal.org/project/webfm

tomgf’s picture

I don't think that you have to modify the field_data_body (or field_revision_body) if the files are inserted there using the filter [[media]]:

[[{"type":"media","view_mode":"media_small","fid":"165","attributes":{"class":"media-image","height":"50px","width":"100px"}}]]

If you modify the location of the file in table file_managed – and clear the cache – the field_data_body will reflect this, as you are not modifying the fid.

I will try to start coding a module to do so as soon as I can…

JacobSingh’s picture

Category: support » feature
rickmanelius’s picture

I agree. Throwing all the files in the top level of the files directory is very unappealing to me. But using something like post #5 above would be amazing.... so that we can organize it in the back end.

rodrigoaguilera’s picture

suscribe

dddbbb’s picture

Subscribing. I'd love to see this improved too. I think an optional year/month automated storage setup like the one suggested in #5 would be a smart move.

effulgentsia’s picture

Title: Change upload directory » Provide administrator with ability to customize upload directory, globally and per-field, with token integration
Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Component: Documentation » Code

+1 to this feature request.

dddbbb’s picture

A clean up of existing files on install would also be great news for anyone already using this module that wants to take advantage of such a feature.

anavarre’s picture

Subscribing

effulgentsia’s picture

Marked #1161420: Change file paths based on tokens a duplicate. There's also an issue in the FileField Paths project (#1161524: Integrate with the Media module) that could help with this.

damienmckenna’s picture

Subscribing, given I opened the other two issues mentioned in #15 ;-)

rwohleb’s picture

subscribe

deciphered’s picture

Just a quick note, as soon as I get back to FileField Paths, I will be making absolute certain that it works with Media, though as Media uses Fields, there is no reason it should require any extra work.

damienmckenna’s picture

@Deciphered: that'll be awesome!

deciphered’s picture

No promises on time frame, current schedule is: Custom Formatters 7.x-2.x, Wysiwyg Fields 6.x-1.x/7.x-1.x then FileField Paths 7.x-2.x

yareckon’s picture

sub.

glottus’s picture

subscribing

chiebert’s picture

Sub

g76’s picture

sub

joostvdl’s picture

subscribe

From the WYSIWYG editor it is not possible to select an directory where to store the files/images.

aaron’s picture

and #1201936: Move the media field to a non-required submodule, which points the way to a new paradigm :D

gusaus’s picture

With #1166168: Expose a widget for filefield and imagefield, so that media browser can be used for them working, I'm able to create a subdirectory for each field. There's still a problem in that the media browser will only upload to whatever is selected as the default download method for the entire site.
#1069582: How to use an alternate stream wrapper when saving media files?

Pocketpain’s picture

sub

Niklas Fiekas’s picture

Subscribe.

JoshHamilton’s picture

Subscribe.

Poieo’s picture

Subscribing

kgrigsby@mac.com’s picture

Subscribe

montchr’s picture

subscribe

dave reid’s picture

dave reid’s picture

Status: Active » Closed (duplicate)