【问题标题】:Size of uploaded video is 0 on the server, even though the video has a size上传视频的大小在服务器上为 0,即使视频有大小
【发布时间】:2021-01-23 13:00:09
【问题描述】:

我有以下 re-frame 事件处理程序,我正在尝试将视频上传到服务器:

(reg-event-fx
 :upload-shot-video-server
 (fn [coeffects [_ blob]]
   (let [body (js/FormData.)]
     (.append body "video" blob)
     {:http-xhrio {:method :post
                   :uri (str "http://d18a6571c2e5.ngrok.io" "/api/upload-shot-video")
                   :body body
                   :on-success [:upload-success]
                   :on-failure [:upload-error]
                   :response-format (edn/edn-response-format)}}))
 )
(reg-event-fx
 :upload-shot-video
 (fn [coeffects _]
   (prn "uploading video")
   (let [response (js/fetch (-> coeffects :db :shot-video-uri))]
     (try
       (go
         (let [blob (<p! (. (<p! response) blob))]
           (js/console.log "blob is " blob)
           (js/console.log "size of blob is " (.-size blob))
           (dispatch [:upload-shot-video-server blob])))
       (catch js/Error e (js/console.log "Error is " e)))
     {})))

我在服务器上有一个处理程序来获取输入流并将其保存为文件:

(defn upload-shot-video [req]
  (prn "uploading video")
  (prn "video is! " (-> req :params))
  (prn "video is " (-> req :body))
  (clojure.java.io/copy (-> req :body) (clojure.java.io/file "./resources/public/video.mov"))
  (let [filename (str (rand-str 100) ".mov")]
    (s3/put-object
     :bucket-name "humboi-videos"
     :key filename
     :file "./resources/public/video.mov"
     :access-control-list {:grant-permission ["AllUsers" "Read"]})
    (db/add-video {:name (-> req :params :name)
                   :uri (str "https://humboi-videos.s3-us-west-1.amazonaws.com/" filename)}))
  (r/response {:res "okay!"}))

但是,保存为文件的视频大小为 0 字节,即使视频 blob 是非零大小的视频。

如何解决这个错误?

【问题讨论】:

    标签: http clojure clojurescript re-frame


    【解决方案1】:

    可能是您的服务器拒绝大文件吗?我正在使用org.httpkit.server,它会默默地拒绝post 8MB 以上的文件。我是这样解决的:

    (server/run-server app {:port your-port-number :max-body 128000000})) ;128MB

    【讨论】:

    • 文件大小不是很大。它小于 8 mb。
    猜你喜欢
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多