HaschekSolutions / pictshare

:camera: PictShare is an open source image, mp4, pastebin hosting service with a simple resizing and upload API that you can host yourself. :rice_scene:
https://www.pictshare.net
Apache License 2.0
819 stars 123 forks source link

Unsupported filetype for valid image using geturl.php #108

Closed dessalines closed 4 years ago

dessalines commented 4 years ago

Could you help me test this seemingly valid image with geturl.php?

https://MY_PICTSHARE.com/pictshare/api/geturl.php?url=https://i.guim.co.uk/img/media/4d908693e566fdd7f8cdeac559f6375b739887a3/356_37_3264_1958/master/3264.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctZGVmYXVsdC5wbmc&enable=upscale&s=3a70177dcc60673c606302d96fcbd9bc

Error:

filetype: "x-empty"
reason: "Unsupported filetype"
status: "err"

geek-at commented 4 years ago

are you using the docker container or did you install it yourself?

If it's the latter it looks like you're missing some libraries.. does the server have the file command?

dessalines commented 4 years ago

Its using shtripok's docker (necessary for arm compatibility too I think). My docker-compose.yml section:

  pictshare:
    image: shtripok/pictshare:latest
    ports:
      - "127.0.0.1:8537:80"
    volumes:
      - pictshare:/usr/share/nginx/html/data
    restart: always

Did you test this one out?

edit: I also forgot to mention, that most urls work, its just some don't.

geek-at commented 4 years ago

Actually the latest official docker images detect the architecture and should work on ARM without a problem

But it seems that the site you're using is checking some sessions or something because when I open your image in the browser it works

But when I download it with curl

curl "https://i.guim.co.uk/img/media/4d908693e566fdd7f8cdeac559f6375b739887a3/356_37_3264_1958/master/3264.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctZGVmYXVsdC5wbmc&enable=upscale&s=3a70177dcc60673c606302d96fcbd9bc"

It's answering with

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>401 Unauthorized - missing signature</title>
  </head>
  <body>
    <h1>Error 401 Unauthorized - missing signature</h1>
    <p>Unauthorized - missing signature</p>
    <h3>Guru Mediation:</h3>
    <p>Details: cache-vie21641-VIE 1582891201 3100362804</p>
    <hr>
    <p>Varnish cache server</p>
  </body>
</html>

So it's not a problem with Pictshare, it's the caching server that required some headers probably

dessalines commented 4 years ago

Hrm this is strange... when I run that exact same curl command on my local machine, it does download the picture fine. What curl you on?

curl --version
curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1d zlib/1.2.11 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh2/1.9.0 nghttp2/1.39.2
geek-at commented 4 years ago

Sorry I copied the link after I put it in my browser.

when you curl with the original link you posted

curl "https://i.guim.co.uk/img/media/4d908693e566fdd7f8cdeac559f6375b739887a3/356_37_3264_1958/master/3264.jpg\?width\=1200\&height\=630\&quality\=85\&auto\=format\&fit\=crop\&overlay-align\=bottom%2Cleft\&overlay-width\=100p\&overlay-base64\=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctZGVmYXVsdC5wbmc\&enable\=upscale\&s\=3a70177dcc60673c606302d96fcbd9bc"

You'll get the error. It seems one of the variables attached to the image is a session ID that's not available for long

dessalines commented 4 years ago

That one is different than the link I posted at the top, it seems to have a lot of extra slashes.

This command is correctly downloading the image: curl "https://i.guim.co.uk/img/media/4d908693e566fdd7f8cdeac559f6375b739887a3/356_37_3264_1958/master/3264.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctZGVmYXVsdC5wbmc&enable=upscale&s=3a70177dcc60673c606302d96fcbd9bc" -o test_img

geek-at commented 4 years ago

Did you rawurlencode the URL before attaching it to https://MY_PICTSHARE.com/pictshare/api/geturl.php?url= ? because that url has "&" and "?" in it so if you use

https://MY_PICTSHARE.com/pictshare/api/geturl.php?url=https://i.guim.co.uk/img/media/4d908693e566fdd7f8cdeac559f6375b739887a3/356_37_3264_1958/master/3264.jpg?width=1200&height=630&quality=85&auto=format&fit=crop&overlay-align=bottom%2Cleft&overlay-width=100p&overlay-base64=L2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctZGVmYXVsdC5wbmc&enable=upscale&s=3a70177dcc60673c606302d96fcbd9bc

Pictshare would only see url=https://i.guim.co.uk/img/media/4d908693e566fdd7f8cdeac559f6375b739887a3/356_37_3264_1958/master/3264.jpg which will return an invalid image.

if you rawurlencode it to https%3A%2F%2Fi.guim.co.uk%2Fimg%2Fmedia%2F4d908693e566fdd7f8cdeac559f6375b739887a3%2F356_37_3264_1958%2Fmaster%2F3264.jpg%3Fwidth%3D1200%26height%3D630%26quality%3D85%26auto%3Dformat%26fit%3Dcrop%26overlay-align%3Dbottom%252Cleft%26overlay-width%3D100p%26overlay-base64%3DL2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctZGVmYXVsdC5wbmc%26enable%3Dupscale%26s%3D3a70177dcc60673c606302d96fcbd9bc

and attach it encoded to the api, it works on my end

https://MY_PICTSHARE.com/pictshare/api/geturl.php?url=https%3A%2F%2Fi.guim.co.uk%2Fimg%2Fmedia%2F4d908693e566fdd7f8cdeac559f6375b739887a3%2F356_37_3264_1958%2Fmaster%2F3264.jpg%3Fwidth%3D1200%26height%3D630%26quality%3D85%26auto%3Dformat%26fit%3Dcrop%26overlay-align%3Dbottom%252Cleft%26overlay-width%3D100p%26overlay-base64%3DL2ltZy9zdGF0aWMvb3ZlcmxheXMvdGctZGVmYXVsdC5wbmc%26enable%3Dupscale%26s%3D3a70177dcc60673c606302d96fcbd9bc

returns

{
  "status": "ok",
  "hash": "o5x75s.jpg",
  "url": "https://pictshare.net/o5x75s.jpg",
  "filetype": "jpeg",
  "delete_code": "z11o0dyzgwdg6oqz08zrx4h18d0vvw",
  "delete_url": "https://pictshare.net/delete_z11yzgwdg6oqz08zigrx4h18d0vvw/o5x75s.jpg"
}
dessalines commented 4 years ago

That did it, thanks!