Nextcloudで画像ファイルをURL共有してWebに埋め込んで利用したい

NextcloudでURL共有した画像をblogなどに埋め込む方法のメモです.今回はNextcloud 20.0.8ですが,Nextcloud 13.0.0から可能になった機能のようです.
共有単位は画像ファイル単体はOKですが,画像ファイルを含むディレクトリ共有ではうまく動かないようです.

20210311 18:03:55 252379

共有したい画像を共有

20210311 18:03:42 228558

「URLで共有」の右の「+」で共有

20210311 18:03:55 228828

URL共有されてURLがコピーされる

20210311 18:03:19 229349

既定値では共有有効期限が1週間に設定されているのでずっと公開したい場合は「有効期限を設定」のチェックを外す

20210311 18:03:02 234008

共有されたURLを開くとプレビューになる

画像をクリックすると,画像が開ける.
若しくは共有URLに /preview を追加する.
拡張子がないとうまく動作しないsiteなどの場合は,/preview?dummy.jpg などのように /preview の後ろにさらにそれらしい文字列を追加すると開けたりする.

https://files.matoken.org/index.php/s/bsaAdtxp8WgXLXE (1)
https://files.matoken.org/index.php/s/bsaAdtxp8WgXLXE/preview (2)
https://files.matoken.org/index.php/s/bsaAdtxp8WgXLXE/preview?/dummy.jpg (3)
  1. 共有URL(プレビューURL)
  2. URL末尾に /preview をつけると画像が表示される
  3. /preview の後ろにダミーファイル名をつける

後は普通に静的画像URLのようにして使えます.

$ wget -o /dev/null -O - https://files.matoken.org/index.php/s/bsaAdtxp8WgXLXE/preview | pee "file -" display
/dev/stdin: JPEG image data, JFIF standard 1.01, resolution (DPI), density 96x96, segment length 16, comment: "CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90", baseline, precision 8, 512x342, components 3
preview

blogに貼り付けもできる :)

環境
$ sudo -u www-data php occ --version
Nextcloud 20.0.8
$ dpkg-query -W php mariadb-server apache2
apache2 2.4.38-3+deb10u4
mariadb-server  1:10.3.27-0+deb10u1
php     2:7.3+69
$ lsb_release -dr
Description:    Debian GNU/Linux 10 (buster)
Release:        10
$ uname -m
x86_64

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)