user8096456
user8096456

Reputation:

How to generate Unique Filename everytime a user upload an image using Blob,FileSave,javascript?

Here's the thing. I have a filepath in my code behind that sends the image file in SQL database and save the image to a specified folder. Also, I have a customization canvas that allows user to customize and design their order. I am using Blob filesave to save that customized design and my problem is I don't know how to generate a UNIQUE filename since when I upload the same filename, it will update (delete the old file name and replace the recent one) to the folder. Is it possible to generate a unique filename?

HTML&Script

  <input type="button" id="saveImg" value="Save Image"/>
 <script>
        $("#saveImg").click(function(){
            $("#canvas").get(0).toBlob(function(blob){ 
                saveAs(blob, "myImg.png");
               
        });
        });
        </script>

enter image description here

enter image description here

Upvotes: 1

Views: 6278

Answers (1)

gvfordo
gvfordo

Reputation: 189

The comments about doing this server side, or proxying from some other unique id, are probably good advice to consider.

However if you just want a unique string to name a file with, you can generate a uuid for it. (I'd use a library) . Uniqueness of a uuid is all but a guarantee (needs something like trillions a day for thousands of years to expect a dupliacte).

Upvotes: 1

Related Questions