Neophen

Neophen

External uploads custom metadata

Is there a way to add custom meta data back to entry after the upload?

import { UploadClient } from '@uploadcare/upload-client'

const client = new UploadClient({ publicKey: "publicKey" })

const Uploadcare = (entries, onViewError) => {
    const uploadEntry = makeEntryUploader(onViewError)
    entries.forEach(uploadEntry)
}

const makeEntryUploader = (onViewError) => async (entry) => {
    const onProgress = ({ isComputable, value }) => {
        if (isComputable) {
            let percent = Math.round(value * 100)
            if (percent < 100) { entry.progress(percent) }
        }
    }

    const abortController = new AbortController()
    onViewError(() => abortController.abort())
    const result = await client.uploadFile(entry.file, {
        onProgress,
        signal: abortController.signal,
    })

    // How to add the data to the entry?
    entry.meta = {
        ...entry.meta,
        // This doesn't work:
        uploadcare: result
    }
    entry.progress(100)
}

const uploaders = {
    Uploadcare,
}

export default uploaders

I have this in the live view:

defp presign_upload(entry, socket) do
    meta = %{uploader: "Uploadcare"}
    {:ok, meta, socket}
end

But I only get the url and stuff in the response from the await client.uploadFile(entry.file, {

Has anyone ran into this? Do I need move the uploading to the server side to get the required data?

Marked As Solved

Neophen

Neophen

For anyone else interested this is the current solution i arrived at.
It’s a hack with the least amount of indirection that i could come up with.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement