When Configuring a Page display for a View, select "File: Path (Path)" as one of the fields (see attached screenshot Selected Fields).
Edit the "File: Path (Path)" field by selecting the "Display download path instead of file storage URI" option (see attached screenshot Download Path Instead Of File Storage URI).
In the preview of the Page, the download path is displayed instead of the file storage URI (see attached screenshot Views Preview).
When the Services display of the View is configured the same way, the file storage URI is still displayed instead of the download path (see attached screenshot Services Preview).
I am requesting that the Services display recognize the selection of the 'Download path instead of file storage URI' option and display the download path.
Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| Services Preview.png | 45.92 KB | Vito Andolini | |
| Views Preview.png | 41.97 KB | Vito Andolini | |
| Download Path Instead Of File Storage URI.png | 56.02 KB | Vito Andolini | |
| Selected Fields.png | 16.3 KB | Vito Andolini |
Comments
Comment #1
Vito Andolini commentedOK, I figured out how to do this. I am a complete newbie to both Drupal and PHP, so I don't know how to create a patch to the module or anything. But the code to do it is below. Basically I updated the execute method with the lines in between the // START CHANGE HERE and // END CHANGE HERE lines. All this does is return a download URL for a file instead of the file storage URI *if* the user selected that option.
My php skills are 0, so maybe you guys know a better way to do this. If this could make it into the next release, that would be great. Thanks so much for providing this great module.
Comment #2
Vito Andolini commentedThis code is actually a little cleaner:
Comment #3
ygerasimov commentedThank you for the solution. I think proper way to accomplish this is to use views_php module and build downloadable url using some custom php code.
Comment #4
focal55 commentedTo follow ygerasimov, using a views_php field you can grab the uri value from the $data object and pass it to file_create_url to print.
Note that you need to create a relationship to the file with "File Usage: File".
Comment #6
admataz commentedI would vote for the suggested functionality in Vito's code in #1790956-1: Services View Always Shows File Storage URI Instead of Download Path for File Path Field to be added - it doesn't make sense for a Service to generate File Storage URIs - there is no way for external systems to consume these URIs, and this is the purpose of this module. The views_php solution may work, but seems like an extra hack for something that should be part of the way services_views generates file paths.
Comment #7
msakurada commentedThis does work on version 7.x-1.0-beta2 w/ views 7.x-3.6 and services 7.x-3.3 downloaded today. you do have to create a File Usage: File relationship but it outputs a real URL Path:
Comment #8
ygerasimov commented@msakurada thank you for this solution. It is way more elegant than using php code!
Comment #10
dsrikanth commented@msakurada: Did you add Views PHP or anything else? I use the same versions mentioned by you but still getting public://filename.jpg. Yes, I have the File Usage: File relationship...
Comment #11
Raphael Dürst commented@dsrikanth: I just had the same problem. In the views preview, it shows the file storage URI (public://filename.jpg), but if you actually look at the real output of the service, you get the download path.
Comment #12
Zheko commentedHere's my solution for this issue. Maybe help for someone.
Comment #13
dsrikanth commentedI can confirm that the File Usage relationship and adding the File Path field with "Display download path instead of file storage URI " enabled works.
Services Version: 7.x-3.12
Services Views Version: 7.x-1.1
Views Version: 7.x-3.11