54350

Best way to store images in PostgreSQL [duplicate]

Question:

This question already has an answer here:

<ul><li> <a href="/questions/54500/storing-images-in-postgresql" dir="ltr" rel="nofollow">Storing Images in PostgreSQL</a> <span class="question-originals-answer-count"> 6 answers </span> </li> </ul>

I am working on a web site that will start off with hundreds of thousands of images in it to hopefully hundreds of millions. Most of the images won't exceed 300K in physical size. What is the best way to store these in PostgreSQL? One thing I know for sure is that the system will be using schemas, partitions, and tablespaces to manage storage.

Answer1:

If the images do not exceed 300Kb, the easiest way is to use a bytea field. The images are saved in the database: a simple backup will include the images.

Or, PostgreSQL can handle large objects: <a href="http://www.postgresql.org/docs/9.3/static/largeobjects.html" rel="nofollow">http://www.postgresql.org/docs/9.3/static/largeobjects.html</a> with which the images will be stored externally to the database.

Alternatively, you can leave the images in the file system, save in a text field the path and use two stored functions (for example in pl/python) that allow you to write and read the external file to store and retrieve images.

Recommend

  • SQL Service Broker: Collecting data from distributed sources.
  • Custom partiotioning of JavaDStreamPairRDD
  • new spark.sql.shuffle.partitions value not used after checkpointing
  • Changing Entity's State in Entity Framework 4.1
  • Powerpoint VBA Macro Save As Dialog File Filter
  • Hadoop shuffle uses which protocol?
  • Is creating a new version of an object in AWS S3 eventually consistent or read-after-write consisten
  • Replace HTML links with text
  • Floating-point number in Excel
  • Linux over commit heuristic
  • HTML code to upload images
  • NSMutableArray Access Issue
  • Nodejs bluebird promise fails while processing image
  • SSIS Designer is running VERY slowly
  • How to add the custom button on google's(device) native application in android?
  • Running jasmine tests for a component with NgZone dependency
  • How to resolve permission denied maybe missing internet permission?
  • Android onKey w/ virtual keyboard
  • Compare struct to a constant in C
  • Django Haystack Rebuild Index
  • WPF Template Binding in ToggleButton UserControl
  • Clarification on min distance on LocationManager.requestLocationUpdates method, min Distance paramet
  • Android - Material Design - NavigationView - How to put vertical scroll?
  • Atlas images wrong size on iPad iOS 9
  • Change multiple background-images with jQuery
  • How do I change content of ComboFieldEditor?
  • Retrieving value from sql ExecuteScalar()
  • Android screen density dpi vs ppi
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Change an a tag attribute in JavaScript based on screen width
  • Weird JavaScript statement, what does it mean?
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Do I've to free mysql result after storing it?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Proper folder structure for lots of source files
  • SQL merge duplicate rows and join values that are different
  • KeystoneJS: Relationships in Admin UI not updating
  • Hits per day in Google Big Query
  • How does Linux kernel interrupt the application?
  • Checking variable from a different class in C#