moodle-tool_objectfs
moodle-tool_objectfs copied to clipboard
Image preview cause pulling images from external storages
Objectfs pulls files locally each time when get_local_path_from_hash()
method gets invoked.
This method is used to preview images and get their width, height and mimetype.
So even if pre-signed urls feature is enabled we have this scenario:
- user opens a page with image (preview, like in private files page);
- Objectfs pulls down the image to let Moodle check its attributes;
- Objectfs updates db and marks this file as diplicated;
- Objectfs generates pre-signed url and feeds it to user;
- then
delete
task picks this file up and deletes it locally.
If some image is frequently asked it might cause excess traffic and unnessesary work to download, update db, delete, update db and agian.
It would be good to extend stored_files get_imageinfo()
method and replace $path
to external url to file. getimagesize
works fine with urls as well.
https://tracker.moodle.org/browse/MDL-70368
I just did a quick experiment, jpeg headers are at the start of the file, you can do a brutal partial byte dumb of a file and the exif info still works:
$ head -c 1000 babyyoda.jpeg > babyyoda.header.jpeg
$ ls -lh babyyoda.*
-rw-r--r-- 1 brendan brendan 1000 Dec 14 15:46 babyyoda.header.jpeg
-rw-r--r-- 1 brendan brendan 189K Dec 14 15:35 babyyoda.jpeg
$ exiftool babyyoda.header.jpeg
ExifTool Version Number : 10.80
File Name : babyyoda.header.jpeg
Directory : .
File Size : 1000 bytes
File Modification Date/Time : 2020:12:14 15:46:44+11:00
File Access Date/Time : 2020:12:14 15:43:44+11:00
File Inode Change Date/Time : 2020:12:14 15:46:44+11:00
File Permissions : rw-r--r--
File Type : JPEG
File Type Extension : jpg
MIME Type : image/jpeg
Image Width : 1200
Image Height : 900
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:2:0 (2 2)
Image Size : 1200x900
We should be able to just grab the stream and download 1 or 2kb into temp and run get_imageinfo on that
Just tested this with a png as well as also works with a 1k header chunk
The tracker has just landed so I think we can close this
https://tracker.moodle.org/browse/MDL-70368