GithubHelp home page GithubHelp logo

Comments (7)

simonw avatar simonw commented on June 9, 2024

Maybe a configuration query that looks this:

select binary_content from files where key = :key

from datasette-media.

simonw avatar simonw commented on June 9, 2024

I tested this branch with a files.db database with the following table and it worked:

CREATE TABLE [photos] (
   [key] TEXT,
   [contents] BLOB
);

Then this in metadata.json:

{
    "plugins": {
        "datasette-media": {
            "photo_from_db": {
                "sql": "select contents as binary_content from photos where key=:key",
                "database": "files"
            }
        }
    }
}

Images were then served from http://127.0.0.1:8001/-/media/photo_from_db/key-for-image

from datasette-media.

simonw avatar simonw commented on June 9, 2024

This could also be made available as one or more output renderers, which you would enable in the config:

{
    "plugins": {
        "datasette-media": {
            "enable-output-renderer": true
        }
    }
}

This could add .raw which dumps out the raw data.

Needs to be done carefully - don't want to accidentally open up HTML injection attacks (people who request .raw for select '<b>evil_html</b>' as output).

from datasette-media.

simonw avatar simonw commented on June 9, 2024

This should be compatible with https://www.sqlite.org/sqlar.html - which can store files using DEFLATE compression.

from datasette-media.

simonw avatar simonw commented on June 9, 2024

sqlite-utils 2.12 is out now with the new insert-files command, useful for testing this issue.

from datasette-media.

simonw avatar simonw commented on June 9, 2024

Don't forget to update this paragraph at the top of the README:

Use this when you have a database table containing references to files on disk that you would like to be able to serve to your users.

from datasette-media.

simonw avatar simonw commented on June 9, 2024

One way to support sqlar: allow a should_deflate column to be returned which tells the plugin to run deflate on the content.

Custom queries against sqlar can then use length(content) < Szabo as should_deflate

from datasette-media.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.