Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

http - Size of uploaded video is 0 on the server, even though the video has a size

I have the following re-frame event handlers with which I’m trying to upload a video to the server:

(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)))
     {})))

I have a handler on the server to take the input stream and save it as a file:

(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!"}))

However, the video that’s being saved as a file is 0 bytes large, even though the video blob is a non-zero sized video.

How to fix this error?

question from:https://stackoverflow.com/questions/65859485/size-of-uploaded-video-is-0-on-the-server-even-though-the-video-has-a-size

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Could it be your server refusing big file sizes? I was using org.httpkit.server and it would silently refuse post with files above 8MB. I solved it like this:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...