Naming files when calling Backendless.Files.saveFile(...), how to ensure name is unique?

Hello,

My question is simple, naming is irrelevant for us, we don’t have problem to name files “untitled1”, “untitled2”…“untitledX”, how can we name files without any collision between them?
we develop using nodejs on business logic.

I can think of:
1.define var counter outside of the js class with start value of 0, and then increment it everytimes an image added.
2. define same but static counter inside of js class
3. use atomic counters

what is the best/most logical solution for that

Thanks in advance for any suggestion,
Hassan

Hi Hassan,

I think using the Atomic Counter API in Backendless is the best option. Here’s the documentation:
https://backendless.com/docs/js/ut_atomic_counters_api_js.html

The approach with the counter variable will not work since there are multiple computers in the Backendless cluster and there is no guarantee that the code will be executed in the same machine.

Regards,
Mark