photo / frontend

The official @github repository of the Trovebox frontend software. A photo sharing and photo management web interface for data stored "in the cloud" (i.e. Amazon S3, Rackspace CloudFiles, Google Storage).
https://trovebox.com
Apache License 2.0
1.38k stars 244 forks source link

Download Original doesn't work with ssl and local filesystem #920

Open Notmarrco opened 12 years ago

Notmarrco commented 12 years ago

Hello,

I can't download the original photo when using ssl on my domain + self hosting.

The issue seems to be that it's looking for the "http" url instead of the "https" one :

PHP Warning:          fopen(http://mydomain.com/photos/original/201208/blabla.jpg): failed to open stream: HTTP request failed! HTTP/1.0  404 Not Found

called here libraries/adapters/FileSystemLocal.php on line 52 :

 $fp = fopen($photo['pathOriginal'], 'r');

What can I do to make it call the right url with "https" ?

thx

jmathai commented 12 years ago

@Notmarrco Is the page you're on using SSL? pathOriginal should use whatever the current page is on as it is a relative path.

Also, we have a new URL to download the original photo that might resolve your issue. It's not yet in the master branch though.

Notmarrco commented 12 years ago

yep the all site is using ssl. Furthermore the download url is "https://mydomain.com/photo/7o/download", in https too.

ok, then I will wait until you release this new url. :)

jmathai commented 12 years ago

Hrm, that is the new URL I'm referring to. Back to your original error...

PHP Warning:          fopen(http://mydomain.com/photos/original/201208/blabla.jpg): failed to open stream: HTTP request failed! HTTP/1.0  404 Not Found

Does the file exist at that location? Obviously not, but I'm starting to wonder why.

Notmarrco commented 12 years ago

Nope, the file doesn't exist at that location. However it does exist at the url with "https" !

Notmarrco commented 12 years ago

ok, something strange : when I call https://mydomain.com/photo/7o/view.json, the pathOriginal isn't relative, it's http://mydomain.com/photos/original/201208/blabla.jpg, where I expected /original/201208/blabla.jpg. pathOriginal is correct in the DB. Am I wrong or is there something weird ? I've failed to trace to the point where the "http://mydomain.com/" is added :(

jmathai commented 12 years ago

@Notmarrco if you look at the view.json endpoint there should be a host value. That's what is prepended to the path. Can you confirm? The host is stored with the photo record. If you're using MySql it's in the photo table.

Notmarrco commented 12 years ago

@jmathai yep, the host value in the view.json is the same as the one in mysql, but it's mydomain.com/photos. No 'http'/'https'.

Notmarrco commented 11 years ago

diving back into it :) I just found that in models/Photo.php , the view function calls $this->generateUrlBase($photo) and $this->generateUrlOriginal($photo). I think that these 2 functions should be called with $protocol as second param. Without it the default is "http", and that's why my "pathOriginal" and "pathBase" are wrong in the view.json. Was it made on purpose ?

Still it doesn't work yet, because fopen isn't authorized (error 401) to call 'https://mydomain.com/blabla". :(

This leads to my other question : why do we use the full pathOriginal in FileSystemLocal.php ? it make more sense to me to use a relative local path, isn't it ? it would at least have better performance.

In the meantime i'll see if i can tweek my lighttpd to access the file anyway :)

Notmarrco commented 11 years ago

As a workaround I added a new field in view.json : pathOriginalLocal, in addApiUrls. It's a copy of pathOriginal, before the $protocol and $host are added to it. Then I call fopen( self::normalizePath($photo['pathOriginalLocal']), 'r'); instead of pathOriginal in FileSystemLocal.php.

I'm not sure if it's a good way to do it, so i'll wait for your opinion before i send a pull request. :)

jmathai commented 11 years ago

@Notmarrco Adding $protocol sounds like the right thing to do (I have to have a closer look at why we weren't already).

Can you open a separate issue about the use of fopen and a URL instead of a local path? There's probably a reason but we can discuss it in a separate thread.