I had an itch to use filefield with storage api. So I've written up an integration, just as a starting point. I know the issues with doing this are thick, but I'd like some feedback on what I've done so far:

http://drupal.org/sandbox/cmjns/1133804

Comments

janamills’s picture

How did you get on with this? I'd be happy to chip what I can in if you still need help thought I'm not much of a module developer.

cmjns’s picture

I put it up as a sandbox project (no git access for me, yet).

http://drupal.org/sandbox/cmjns/1133804

Being a sandbox project, it is subject to being broken without prior notice. But when I get back around to actually deploying it for the client for whom it was written, I'm sure it'll see some improvements.

TimeFor’s picture

Brilliant! This is exactly what I was looking for. I've installed your sandbox project and its working pretty well for me. I couldn't find anything other modules that simply take an uploaded file and send it to FTP. This accomplishes just that. I also like how if I remove a file node, the file is also removed from FTP.

The only thing I need to figure out is how to get the storage data back to the node. I've noticed if I upload multiple files with the same name. Storage is appending _0 , _1 to the filename as expected. However the filefield doesn't know anything about this. In my case, I'm not keeping the files locally. So each time I upload example.zip, filefeild stores example.zip in the node. When storage api comes along it passes that file to FTP server and removed it locally. Since there is already an example.zip from a different node, it creates example_0.zip ext... The only downside right now is that the node that second zip was uploaded from still thinks the filename is example.zip.

Great job on the module man. I'll see what I can do to contribute back if I find a nice solution for the filename issue.

TimeFor’s picture

I just noticed your filefield file formatter in your code. This would solve my issue above but its not working for me. Does it work for you?

The key issue seems to be line 39 in filefield_storage.module.

$storage = storage_api_file_load($file['data']['file_id']);

The issue is that storage_api_file_load needs file_id and that data is not in $file['data']['file_id'] there is no ['file_id'] at all in that $file array.

** Update **

This is my super hacky solution to get it working. I don't recommend this but it works well enough to show a concept. Basically since the problem is that I don't have the file_id at the time I'm rendering the file field, I just look it up.

function theme_filefield_storage_formatter_serving_url($element) {

  $file = $element['#item']; //This doesn't include the file_id but it has the fid
  
  $result = db_query('SELECT data FROM {filefield_storage} WHERE fid=%d', $file['fid']);
  
  if (!$result) {
    return t('no result');
  }
  
  $blob = db_fetch_object($result)->data;
  
  /* Unserialize the data */
  $data = array();
  
  $data = !empty($blob) ? unserialize(base64_decode($blob)) : array();
  
  $field = content_fields($element['#field_name']);  
  $storage = storage_api_file_load($data['file_id']); // Now I have the file_id
  
  $icon = theme('filefield_icon', $file);
  if ($storage) {
    if ($url = storage_api_serve_url($storage, $absolute=TRUE)) {
      //$element['#item']['filepath'] = $url;
      $link = l($file['filename'], $url);
      return $output = "<div><span>$icon</span><span>$link</span></div>";
    }
  }
  
  return t('This file currently is unavailable for download');
}

- Jayson

jbrown’s picture

Version: 6.x-1.2 » 6.x-1.x-dev

Thanks for working on this!

The Drupal 7 version of Storage API is actually much more mature than the D6 version (and is very different), although the D7 version hasn't had a stable release quite yet.

The D7 version enables support for file and image fields via Stream Wrappers. D6 does doesn't have this API, so you've implemented it the cleanest way possible using a clever hack.

I'm not interested in maintaining the D6 branch. Does cmjns want to do it? There are 364 sites using it. The filefield integration could ship with the module.

cmjns’s picture

Yea, I'll take over the six branch. Like most people, I'm trying to move past six and start getting my hands dirty with seven. But I can at least address bug fixes and possibly some backports.

cmjns’s picture

Thanks! I'll have a look in the next few days. I'm thinking the best place for that would be in the queue for the sandbox project. However, in the mean time I think the solution I'd go after is to actually get the file_id into the data array. Also, the formatter was almost an afterthought; the last thing I implemented and consequently the least likely to work.

#3 asks about what happens to the file on disk / in storage when the node is deleted. Storage API should handle removing the file, moving the file, etc. All I did was tie those Storage API hooks into filefield hooks. The thing that worries me is that if we let Storage API remove the original file from the location filefield knows about then there may be issues with other modules. Needless to say, this module should NOT be used with, e.g., filefield paths and filefield sources. Anyway, there are issues there to think through.

jbrown’s picture

Thanks cmjns. You should now be able to make pushes to Storage API. drupal.org doesn't yet have per branch permissions, but just stick to 6.x-1.x

If the same issue applies to 6 and 7, then it should be fixed in 7 first (committed by me) and then backported to 6.

Great to have you onboard!!

cmjns’s picture

Glad to be so. Guess I should start working through the issues, huh.

cmjns’s picture

Oh, and sorry for late replies. Just finished moving the family to a new city, so pretty crazy on my end. Should settle down shortly.

ferrangil’s picture

Great to see somebody taking care of the 6.x branch! Subscribing.

designguru’s picture

You know, I'm not even sure what purpose this module serves without filefield integration?! I initially thought that the Storage API module for Drupal 6 would be able to replace local file storage (say the '/sites/default/files' directory) with a remote location but after installing it and setting things up with my S3 account I have no clue how the module works.

I just came across this thread and am super excited to see your progress. To me it seems that this module should work like the AmazonS3 module (ref:http://drupal.org/node/1237446) but that module has no d6 development path...

q./

steeph’s picture

I installed the sandbox project but I'm not sure how to set it up. Please can anybody give me advice on what I need to do so my files get stored on a FTP? I created a container and a class and run cron. But on /admin/build/storage/services it still sais 0 instances for all services I tried. I must be missing something.

steeph’s picture

Oh, OK, I had to enable it for every filefield first. Now it copies the files to FTP but I don't know how to make it so it also uses them instead of the local files.

Perignon’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

I am a new co-maintainer for Storage_API. Drupal 6 is coming toward end of life as soon as D8 is released which should be by the end of 2014. Due to that, I am going to be closing all 6.x issues as it's a hurdle too far to overcome with the amount of issues in the queue against this module.