imagekit-developer/imagekit-uppy-plugin

Error : The token with value "..." has been used before

Closed this issue · 5 comments

Hi everyone !

When I sent multiple images I often get this error on one or more files :

"The token with value '8b0aac7b-2dba-48a5-a3de-04f9737ac470' has been used before. We suggest using V4 UUIDs, or another random string with enough entropy to avoid collisions."

Is usually happen when upload is fast.

I was thinking that is the token on the FileMeta, so I tried :

     .on('file-added', (file) => {
       uppy.setFileMeta(file.id, { id: uuidv4() })
     })

and

     .on('file-added', (file) => {
       uppy.setFileMeta(file.id, { token: uuidv4() })
     })

But I still get the same error.

Do you know which token is it and where the UUID is generated ?

Hi @simoncrypta , Thanks for reporting this issue, however, I am unable to reproduce this. Let me know if you can help with the minimum code to reproduce this problem.

The token etc will be taken care by the plugin if you provide an authenticationEndpoint.

I will share the steps I took.

We use this same plugin in ImageKit media library. I uploaded 200 files and repeated this with different network conditions using Chrome network throttling. I tried "No throttling", "Fast 3G" and "Slow 3G", but there was no error.

I have updated to the last version of uppy and imagekit-uppy-plugin. It seem to work now! Thank you for your help :)

Hi, I have got the same problem. I am using imagekit-uppy-plugin v1.0.2. I have also tried adding your code above, but it doesn't seem to work.

POST https://upload.imagekit.io/api/v1/files/upload 400

loggers.js:15 [Uppy] [11:33:37] Failed to upload 14d033109534235.5fd6416d52916.jpg The token with value 'da84421f-ac73-4a6d-8293-9f92cffe5c30' has been used before. We suggest using V4 UUIDs, or another random string with enough entropy to avoid collisions.

So I have reverse engineered the plugin a bit and it seems as if it is using the token provided by the authentication endpoint and sends it to the upload endpoint. But the authentication endpoint isn't supposed to return something different for each request, is it? If yes, then I have to troubleshoot my authentication backend. If no then how is the token supposed to be different for each request?

Okay, I have found the bug. I saw the the x-cache-status header was set to HIT, indicating that the upload_auth api endpoint was cached. I deactivated the caching with a few hacks and voila it works. For the support team: You might add a big disclaimer to the authentication endpoint documentation that deactivating caching should be enforced.