ฉันมีตัวจัดการเหตุการณ์เฟรมใหม่ต่อไปนี้ซึ่งฉันพยายามอัปโหลดวิดีโอไปยังเซิร์ฟเวอร์:
(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 ไบต์ แม้ว่าวิดีโอหยดจะเป็นวิดีโอที่มีขนาดไม่เป็นศูนย์ก็ตาม
จะแก้ไขข้อผิดพลาดนี้ได้อย่างไร?