Image Upload Fails

PCHome's profile image PCHome posted 3 weeks ago in General Permalink

Rights and wrongs aside on putting a blob into a database, I'm trying to update an existing entry with a new image and there are no errors but it fails. I'm running HeidiSQL on WINE in Ubuntu as I've been doing for years and have never encountered this issue before. Although I'm sure it needs to use the Windows path type, I also tried the Linux path but it made no difference. Any ideas?

The query itself is simple:

UPDATE images_site SET Image = LOAD_FILE('Z:\home\don\Pictures\Alan.png') WHERE ID = 10035;

ansgar's profile image ansgar posted 3 weeks ago Permalink

If there are no errors then in what way does it fail?

PCHome's profile image PCHome posted 3 weeks ago Permalink

It says 0 rows affected and the image isn't there.

ansgar's profile image ansgar posted 3 weeks ago Permalink

I tested the same on Windows 11 with MariaDB 10.3 and also get NULL values in the table.

Duplicating the directory slashes made it work:

UPDATE images SET img=LOAD_FILE('C:\\Temp\\bb147fad65bc1744.jpg') WHERE id=1;
PCHome's profile image PCHome posted 3 weeks ago Permalink

Interesting! Any idea why that is, Anyway, I tried it but still nothing.

UPDATE `images_site` SET `Image` = LOAD_FILE('Z:\\home\\don\\Pictures\\Alan.png')
     WHERE `ID` = 10035;
/* Info: Rows matched: 1  Changed: 0  Warnings: 0 */
/* Affected rows: 0  Found rows: 0  Warnings: 0  Duration for 1 query: 0.001 sec. */
ansgar's profile image ansgar posted 3 weeks ago Permalink

I'm not an expert for Wine, but I think the server needs a native Unix path as it does not run through Wine and knows nothing about such Windows paths, or?

PCHome's profile image PCHome posted 3 weeks ago Permalink

I was wondering about that too and had tried it both ways before posted to you s I wasn't sure but it didn't work either. HeidiSQL's own Blob insert tool, which does not seem to have a way to specify a row to use, uses Windows paths. Anyway, I'll try again.

PCHome's profile image PCHome posted 3 weeks ago Permalink

Just tried again using the Linux path but no difference and on an off-chance I also tried the double-slashes but that didn't work either. No error and Null value. However, I also tried it in Antares, a Linux-based MySQL manager and still no-go so there is likely something wrong in the query that I'm missing. I had a look at the file permissions and they all seem proper although if they weren't, I would expect HeidiSQL or Antares to give an error rather than none at all.

PCHome's profile image PCHome posted 3 weeks ago Permalink

This might be a clue so I'll move the image into the Apache space to see if it helps.

If using LOAD_FILE() to insert images, MySQL's secure_file_priv system variable restricts the directories from which files can be loaded.

PCHome's profile image PCHome posted 3 weeks ago Permalink

That wasn't it either even though it seemed promising.

Please login to leave a reply, or register at first.