[DB] DB에 이미지를 저장하는 여러가지 방법

2024. 5. 6. 16:59정보보안 및 해킹/웹 개발

데이터베이스에 이미지를 저장하는 방법에는 여러가지 방법이 있는데, 본 포스팅에는 총 4가지 방법을 소개하고 싶다.

 

이미지 자체를 BLOB로 저장

이미지 데이터를 LONGBLOB데이터로 변환하여 DB에 저장한다

BLOB(Binary Large Object)라고 하여, 최대 2,147,483,647길이의 가변길이 이진 문자열이라고 한다.

이미지를 Base64로 저장

이미지를 Base64로 인코딩하여 저장한 후 읽어올 때에도 디코딩하여 읽어오는 방법이 있다.

Base64는 64진법으로 0부터 63까지 사용하면서도 최대한 데이터 손상을 최소화할 수 있어서 많이 사용되고 있는 것으로 보인다.

보통 Mobile Application에서 띄울 때 많이 사용하는 방식인 것으로 보인다.

이미지 전체 경로를 저장

이미지를 불러오는 전체 경로를 저장하는 방법이다.

이미지를 옮기는 경우 경로를 전부 바꿔야하는 불편함이 있으므로 조금은 비추천

이미지 부분 경로를 저장

이미지를 불러오는 부분 경로를 불러오는 방법이다.

보통 이미지 폴더가 php가 있는 곳에 함께 위치해있으며, 클라이언트가 이미지를 업로드 하면 그 폴더에 저장이 되고 서버에는 그 경로가 저장이 되는 식으로 구현이 된다.

가장 많이 사용되는 방법이다.

 

ref. https://www.sitepoint.com/community/t/how-to-insert-an-image-on-to-phpmyadmin-is-it-blob-type/114937/6

 

How to insert an image on to phpmyadmin? is it BLOB type?

That takes care of the upload part - then you just need to load the image into the database (which the code you posted doesn’t show). It is usually recommended that the image also be kept as a file as that is much faster to access. The database copy woul

www.sitepoint.com

https://docs.oracle.com/javadb/10.8.3.0/ref/rrefblob.html

 

BLOB data type

A BLOB (binary large object) is a varying-length binary string that can be up to 2,147,483,647 characters long. Like other binary types, BLOB strings are not associated with a code page. In addition, BLOB strings do not hold character data. The length is g

docs.oracle.com

https://www.sololearn.com/en/Discuss/523334/i-need-to-save-an-image-in-a-data-base-phpmyadmin-how-can-i-do-it

 

I need to save an image in a data base phpMyAdmin ? how can I do it? | Sololearn: Learn to code for FREE!

I try to save the image not here link .

www.sololearn.com

https://velog.io/@byeol4001/Base-64%EC%99%80-base64-img-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0

 

Base 64와 base64 img 사용하기

html에 img의 src에 url이 아닌 숫자와 문자로 구성된 긴 코드가 들어간 경우가 있었는데 data:image/png;base64와 같은 형태였다.검색 후 아래와 경우에는 이미지를 base64인코딩 방식으로 사용한다는것을

velog.io

https://www.geeksforgeeks.org/how-to-upload-image-into-database-and-display-it-using-php/

 

How to Upload Image into Database and Display it using PHP ? - GeeksforGeeks

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

www.geeksforgeeks.org

 

 

근데 왜 나는 안되냐