如何使用Sequel和Sinatra将图像插入到SQLite中?

时间:2021-05-28 11:00:06

I'm trying to insert images to each one of my blog posts using SQLite with Sequel and Sinatra.

我正在尝试使用带有Sequel和Sinatra的SQLite在我的每篇博文中插入图像。

DB.create_table :posts do
primary_key :id
String :title
String :content
Datetime :created_at
Datetime :updated_at
foreign_key(:user_id, :users, :type=>String)
end

What changes should I make to my db for that and how can insert the image from the view and later display it?

我应该对我的数据库进行哪些更改以及如何从视图中插入图像并稍后显示它?

Any help or idea is highly appreciated.

任何帮助或想法都非常感谢。

1 个解决方案

#1


0  

Personally, if it's for a blog then I'd upload the file somewhere - whether that be a filesharing site (your Dropbox or something), and then write an img link to it in the article's text. Why complicate things?

就个人而言,如果它是一个博客,那么我会将文件上传到某个地方 - 无论是文件共享网站(你的Dropbox还是其他东西),然后在文章的文本中写一个img链接。为什么复杂的事情?

Edit: I'm not suggesting embedding HTML in your document, but (such as in Markdown) an indicator that is then further processed into HTML later, much as the rest of the document will.

编辑:我不是建议在您的文档中嵌入HTML,而是(例如在Markdown中)一个指示符,然后在以后进一步处理成HTML,就像文档的其余部分一样。

I'd also rename Post to Article, since POST is an HTTP verb and used in Sinatra, or else you end up with stuff like this:

我也将Post重命名为Article,因为POST是一个HTTP动词并在Sinatra中使用,否则你最终会得到这样的东西:

post "/post" do
  post = Post.new title: "First Post"

#1


0  

Personally, if it's for a blog then I'd upload the file somewhere - whether that be a filesharing site (your Dropbox or something), and then write an img link to it in the article's text. Why complicate things?

就个人而言,如果它是一个博客,那么我会将文件上传到某个地方 - 无论是文件共享网站(你的Dropbox还是其他东西),然后在文章的文本中写一个img链接。为什么复杂的事情?

Edit: I'm not suggesting embedding HTML in your document, but (such as in Markdown) an indicator that is then further processed into HTML later, much as the rest of the document will.

编辑:我不是建议在您的文档中嵌入HTML,而是(例如在Markdown中)一个指示符,然后在以后进一步处理成HTML,就像文档的其余部分一样。

I'd also rename Post to Article, since POST is an HTTP verb and used in Sinatra, or else you end up with stuff like this:

我也将Post重命名为Article,因为POST是一个HTTP动词并在Sinatra中使用,否则你最终会得到这样的东西:

post "/post" do
  post = Post.new title: "First Post"