1

I am doing a multi-part file upload using clj-http. I am wondering if there is a way I can track the progress of a file upload. Perhaps, some function that gets called periodically with how much of the file has been uploaded so far?

SAN
  • 79
  • 6

1 Answers1

2

clj-http uses Apache HTTP Client underneath so you can reuse a solution presented in the answer to another question. However, it cannot be easily.

The code presented in the linked answer provides an enhanced implementation of HttpEntity. clj-http currently doesn't support providing your own instance of HttpEntity as your request body.

You have two options:

  1. Provide a pull request to clj-http so it supports providing an instance of HttpEntity as the :body value (e.g. by adding another cond branch checking for HttpEntity value or by making wrap-input-coercion a multimethod so you can extend it for HttpEntity).

  2. Provide similar logic to that from the mentioned FileEntity and OutputStreamProgress but in your implementation of org.apache.http.entity.mime.content.ContentBody. clj-http supports providing them as values for multipart attachments. The drawback here is that it would track progress per attachment, not per the whole request.

Community
  • 1
  • 1
Piotrek Bzdyl
  • 12,965
  • 1
  • 31
  • 49