Liking cljdoc? Tell your friends :D

com.fulcrologic.fulcro.networking.file-upload

cljs

Client-side middleware that can be used with HTTP remotes so that mutations can attach file uploads to mutation parameters.

Client-side middleware that can be used with HTTP remotes so that mutations can attach file uploads to mutation
parameters.
raw docstring

attach-uploadscljs

(attach-uploads params objects-to-upload)

Attach js Blob or ArrayBuffer objects to the params. This requires that you use http-remote and that you also install wrap-file-upload middleware. If you use js/File objects then the filenames of those objects will be available to the mutations on the server.

Example usage:

(let [uploads [(file-upload/new-upload "test" some-js-file)
               (file-upload/new-upload "other" other-js-file)]]
  (comp/transact! this [(some-mutation (attach-uploads {} uploads))]))

If you are using a browser file input, you can use evt->uploads:

(dom/input {:type "file"
            :multiple true
            :onChange (fn [evt]
                        (let [uploads (file-upload/evt->uploads evt)]
                          (comp/transact! this [(some-mutation (file-upload/attach-uploads {} uploads))])))})
Attach js Blob or ArrayBuffer objects to the `params`. This requires that you use `http-remote` and that you
also install `wrap-file-upload` middleware. If you use js/File objects then the filenames of those objects
will be available to the mutations on the server.

Example usage:

```
(let [uploads [(file-upload/new-upload "test" some-js-file)
               (file-upload/new-upload "other" other-js-file)]]
  (comp/transact! this [(some-mutation (attach-uploads {} uploads))]))
```

If you are using a browser file input, you can use `evt->uploads`:

```
(dom/input {:type "file"
            :multiple true
            :onChange (fn [evt]
                        (let [uploads (file-upload/evt->uploads evt)]
                          (comp/transact! this [(some-mutation (file-upload/attach-uploads {} uploads))])))})
```
sourceraw docstring

evt->uploadscljs

(evt->uploads file-input-change-event)

Converts a file input onChange event into a sequence upload objects that are compatible with attach-uploads.

Converts a file input onChange event into a sequence upload objects that are compatible with `attach-uploads`.
sourceraw docstring

new-uploadcljs

(new-upload name content)

Create a new upload object from a string name and a js object (Blob, ArrayBuffer, or File). The resulting map is safe to store in app state.

See attach-uploads.

Create a new upload object from a string name and a js object (Blob, ArrayBuffer, or File). The resulting map is
safe to store in app state.

See `attach-uploads`.
sourceraw docstring

wrap-file-uploadcljs

(wrap-file-upload handler)
(wrap-file-upload handler transit-options)

Adds support for attaching uploads to the parameters of any mutation.

transit-options - A map of options to be included when converting the mutation and params for transmission. See transit/transit-clj->str. Use this to extend the transit support. This is necessary because the regular request middleware will not be used to send transactions that include file uploads, so any extensions to transit must be done in both places.

NOTE: This middleware acts as the end of the chain when it detects the need for a file upload, and rewrites the body, method, and clears any content-type header. As such, it should be used in the middleware so that it will be executed first:

(def client-middleware
  (->
    (net/wrap-fulcro-request)
    (file-upload/wrap-file-upload)
    ...))
Adds support for attaching uploads to the parameters of any mutation.

`transit-options` - A map of options to be included when converting the mutation and params for transmission. See
                    `transit/transit-clj->str`. Use this to extend the transit support. This is necessary because
                    the regular request middleware will not be used to send transactions that include file uploads,
                    so any extensions to transit must be done in both places.

NOTE: This middleware acts as the end of the chain when it detects the need for a file upload, and rewrites the body,
method, and clears any content-type header. As such, it should be used in the middleware so that it will be executed
first:

```
(def client-middleware
  (->
    (net/wrap-fulcro-request)
    (file-upload/wrap-file-upload)
    ...))
```
sourceraw docstring

wrap-mutation-file-uploadsclj

(wrap-mutation-file-uploads handler transit-options)

Middleware that enables the server to handle mutations that have attached file uploads to their parameters. This middleware must be composed after Ring middleware for multipart (required), but before the API handling.

For example:

(->
   ...
   (wrap-api "/api")
   (wrap-file-uploads)
   (wrap-keyword-params)
   (wrap-multipart-params)
   ...)
Middleware that enables the server to handle mutations that have attached file uploads to their parameters.
This middleware must be composed after Ring middleware for multipart (*required*), but
before the API handling.

For example:

```
(->
   ...
   (wrap-api "/api")
   (wrap-file-uploads)
   (wrap-keyword-params)
   (wrap-multipart-params)
   ...)
```
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close