Posted by meppy on September 11, 2008 at 12:01pm
| Project: | Private Upload |
| Version: | 6.x-1.0-rc2 |
| Component: | Miscellaneous |
| Category: | feature request |
| Priority: | normal |
| Assigned: | selinav |
| Status: | needs review |
Issue Summary
If files are marked as private and I have links in a view to the files they do not work as they reference the file directly. Is there a way to have the link reference the file through System in a view?
Comments
#1
Views 1 integration exists, but I (or some other ambitious soul) needs to updated it for views 2.
#2
OK, what would it cost to get you to do that sooner rather than later?
#3
I dont know how to create a patch that includes adding a file.
Here is a first views 2 integration approach that works. Hope to learn something from follow ups ;)
#4
#5
Great, this has been on my TODO list forever. Thanks.
#6
Hi,
I just wanted to know if it is possible to post the patch for version 5 of Drupal? Thanks in advance.
#7
Hi there - I downloaded this new version posted by derjochenmeyer, however my links to download files in views 2 still don't work (they point to the 'files/private/' directory) Is there something I need to do/update in my view to make this work?
thanks in advance!
Sean Porter
#8
Found a similar issue and fix in the Views issues pages #575784: Views + Private Upload: Attached files: 'Link this field to download the file': does not work with private files, it does the job but there are other issues with this fix I've detailed here:
#706672: Private Upload renames duplicate files, but doesn't update File: File Name in views
#9
Sorry for the multiple posts...
I found another work around: in your view (a file-based view, although a node-based view would probably work)
make a relationship to upload : attached files.
then for your field, select group "uploads" and Upload : Attached files
Then label the field as you wish, and select "Link this field to download the file"
this generates the name of the file with proper url. it's still technically displaying the "wrong" file name as I mentioned in that other issue, however this isn't as important since it is pointing to the correct file.
HTH
Sean
#10
Attached is the code from #3 is patch form. It seems to be working for me fine with private uploads 6.x-1.0-rc2 and views 6.x-2.11.
Basically I took the code from derjochenmeyer and did a full directory diff against private uploads 6.x-1.0-rc2. I did make 2 adjustments though:
<?phpline which was leading to a bunch of "Headers already set" php errors. I took me some time to track this down and these characters are removed from the patchI've had good results so far... hope others can review.
If this works for others derjochenmeyer should surely get credit
Best,
Ryan
#11
Hi again,
The patch in #10 had some superfluous code. I also noticed that derjochenmeyer's implementation changed some of the "Upload: Attached File" field options in views (no tokens available, etc.). As a result, I re-worked things a bit in the attached patch so that the views options are now as close to "native" views functionality as possible.
One thing I did notice is that this fix depends on a "private" function (
_private_upload_create_url()) being called from inside a view handler (views_handler_field_upload_fid.inc). I'm assuming this is alright given that the views handler is actually part of the private uploads module? I'm still somewhat new to the Drupal coding standards, so I wanted to ask about this.Best,
Ryan
#12
This patch has proven really handy for me on a couple sites, but I've noticed that there are heaps of views plugins and handlers that could define download links... each of which will continue to create incorrect paths. It seems that this is related to the fact that there is no "file_create_url" hook... so it's up to each module/handler to build the file download link (not Drupal). So I think getting every module/handler to play nice with Private Upload would mean patching every module/handler that builds file paths for node file attachments. I could be wrong about this, but this seems accurate based on some experience.
Anyway, it seems that the only fully robust way I could get private upload supported was to use this patch along with a rewrite (a concept explored at #636516: Option to use "mod_rewrite" in .htaccess rather than "deny from all" (avoid "Access Denied" errors from incorrect file paths)).
#13
You can also rewrite it as a link with the path system/files/private/[upload_fid-name] and uncheck 'Link this field to download the file'.
It works for me.
#14
Hi selinav,
I believe that solution will work well most of the time, but there are some known cases where it does break down. I think things are discussed more at #575784: Views + Private Upload: Attached files: 'Link this field to download the file': does not work with private files (see comment #27 as well as the link to issue #706672). I suppose there may be other non-view modules that output file download links which may get the link structure wrong as well, that's why a rewrite (as discussed in #636516: Option to use "mod_rewrite" in .htaccess rather than "deny from all" (avoid "Access Denied" errors from incorrect file paths)) seems like the most robust solution from what I have learned so far.