Is there way how to rename file with media_mover before uploading to S3?

Comments

arthurf’s picture

There is a renaming process that happens at the code level, but there is no user interaction with it. Is there some functionality that you're looking for?

anantagati’s picture

Yes, I am looking for function to define what name file should have when is uploaded on Amazon S3.

For example user will upload 'document.txt' with cck filefield and I want to save it to Amazon S3 as 'file-node-16.txt'.

I needed to test it quickly so I added few lines to _mm_s3_send() function until I will have better solution.

  $file_name = basename($file['process_file']);
+  // rename file
+  $path_parts = pathinfo($file_name);
+  $file_name = 'node-'.$file['nid'].'.'.strtolower($path_parts['extension']);

I will try to find some time to make module for renaming files with support of tokens from Token.module which can run as process or storage action.

arthurf’s picture

That's an interesting idea. I'd actually like to support it in the core of media mover that modules (like s3) could access so that the naming system could be utilized through out the process. There should probably a call something like media_mover_api_file_name($filename, $configuration) which could rebuild the file name if the token module was present. I'm totally open to suggestions of how to pull it off.