0

I am using a local database and I am trying to insert a image into a Photo VARBINARY(20000) column.

What is the path I have to use to LOAD_FILE?

INSERT INTO ImageTable(PHOTO) VALUES(LOAD_FILE('E:/wamp64/bin/mysql/mysql5.7.14/data/test.jpg'));

Is what I am using. This enter NULL into the table. MySQL is also under this path. Does the path have to be relative to something? I am using the command line.

5
  • 1
    Dont' save files in a database. stackoverflow.com/a/41235395/267540 Commented Jan 7, 2017 at 12:23
  • do you get an error that the file was found or not? If not, then MySQL interprets the file correctly, then you have to look at the file contents. Commented Jan 7, 2017 at 12:27
  • i tried loading a file that is non-existent and it doesnt give any error anyways. @e4c5: I have the string too that I can data:image/jpeg;base64 but it is too long to insert using the command line. Any tips on that? Commented Jan 7, 2017 at 12:28
  • read that answer closely Commented Jan 7, 2017 at 12:29
  • Ok so basically the answer tells me not to do it. But it is sort of a requirement for the app I m working on. I need to insert either the image or the string. Commented Jan 7, 2017 at 12:32

2 Answers 2

1

Actually if you're using image, Varchar is not the right type. You should use BLOB instead. This should cover it:

INSERT INTO ImageTable(PHOTO) VALUES(1,LOAD_FILE('E:/wamp64/bin/mysql/mysql5.7.14/data/test.jpg'));

Search further for BLOB and LONG BLOB to use images.

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry, my mistake. It is of type VARBINARY(20000), not VARCHAR. :( I corrected it in the main post.
Anyway the code i wrote should help. I had the same problem once, only that I was using varchar to find the image path. Intead, BLOB will load the image on the link you insert. :)
Unfortunately, I am working on an existing database and am not supposed to change the column types. But using the absolute path is correct or, this is not a pathing issue?
Not a pathing issue. If the absolute path leads to an image, should work.
0

I disabled --secure-file-priv and it worked. But unsure whether that was the problem because the error message for taht was not shown.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.