我在网上找到了一些样本,但我想从每天使用PHP的人那里获得反馈,以了解潜在的安全性或性能考虑因素及其解决方案.
请注意,我只对一次上传单个文件感兴趣.
理想情况下,不需要浏览器插件(Flash/Java),尽管知道使用插件的好处会很有趣.
我想知道最好的HTML表单代码和PHP处理代码.
在不更改图像的情况下更新包含附加图像的模型时,我无法弄清楚出现错误的原因:
Processing by PostsController#update as JSONAPI
Parameters: {"data"=>{"id"=>"28", "attributes"=>{"title"=>"post-1", "body"=>"azertyui", "archived"=>true, "tag_ids"=>[11, 12, 13], "photo"=>"http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBFZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--86e7464f36c2eddf776573af7b9e61d969287158/diagram.png"}, "type"=>"posts"}, "id"=>"28"}
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.5ms)
ActiveSupport::MessageVerifier::InvalidSignature (ActiveSupport::MessageVerifier::InvalidSignature):
app/controllers/posts_controller.rb:30:in `update'
Run Code Online (Sandbox Code Playgroud)
这是控制器更新操作代码:
def update
if @post.update(post_params)
render json: @post
else
respond_with_errors @post
end
end
Run Code Online (Sandbox Code Playgroud)
这是PostSerializer看起来的样子:
class PostSerializer < ActiveModel::Serializer
include Rails.application.routes.url_helpers
attributes :id, :title, :body, :tag_ids, :archived, :photo
def photo
rails_blob_url(object.photo) if object.photo.attached?
end
end
Run Code Online (Sandbox Code Playgroud)
我正在使用 Rails 5.2.0 API。我错过了什么?