Uploading files with a specific name

Hi I would like to upload the file with a specific name using uploadcare widget.
For example user on my site select a file to upload using the uploadcare widget embedded in form but I want to give the file selected by user a different name like userID
Is there any way I can do that?

Also I want user to upload images only along with pdf as pdf can be a image as well, how can I do that?

After upload, a file gets UUID and you can access the file using its CDN URL. You can add any file name after the last slash, for example :
https://ucarecdn.com/5651bbb6-c599-44bd-9c63-1db5e67db6ad/
https://ucarecdn.com/5651bbb6-c599-44bd-9c63-1db5e67db6ad/cat.jpg
https://ucarecdn.com/5651bbb6-c599-44bd-9c63-1db5e67db6ad/anyname.jpg
All these links refer to the same file.

If you want to allow your users to upload only specified file types you can set it with Preferred types option or use File validaton.

Thanks achernenko.
Actually I have already done that but when I download the file using the code Download’ it still shows the downloaded file name as the original file name uploaded by user.

Is there any way I get the downlaoded file as cat.jpg?

Hi,

I am wondering if someone can help me . I want to allow only particular extensions file to upload through uploadcare widget.
The custom validation function is working but not outputting the error.

Here is my code

HTML <\ script UPLOADCARE_PUBLIC_KEY = “xxxxxxx”; //key related to our account </script>
<\script src=“https://ucarecdn.com/libs/widget/3.1.4/uploadcare.min.js” charset=“utf-8”></script>
<\input type=“hidden” role=“uploadcare-uploader” name=“content” data-file-types=“jpg jpg jpeg gif png tiff bmp webp pdf” data-input-accept-types=“application/pdf images/*” value="" />
"

JS
$(document).ready(function() {
$(‘body’).on(‘submit’, ‘.modal form’, validateForm() );

    UPLOADCARE_LOCALE_TRANSLATIONS = {
        errors: {
            'fileType': 'Only image/pdf files are allowed.'
        },
        dialog: { 
            tabs: { 
                preview: { 
                    error: {
                        'fileType': {  
                            title: 'Upload failed.',
                            text: 'Only image/pdf files are allowed.',
                            back: 'Back'
                        }
                    } 
                } 
            } 
        }
    };

    $uc = uploadcare.jQuery;
    
    function fileTypeLimit(types) {
        types = types.split(' ');
        return function(fileInfo) {
            if (fileInfo.name === null) {
                return;
            }

            var extension = fileInfo.name.split('.').pop();
            if (types.indexOf(extension) == -1) {
                throw new Error("fileType");
            }
        };
    }

    $uc('[role=uploadcare-uploader][data-file-types]').each(function() {
        var input = $(this);
        var widget = uploadcare.Widget(input);
        widget.validators.push(fileTypeLimit(input.data('file-types')));
    });

});

Its not allowing me to upload any files except mentioned in data-file-types input hidden field but not outputting the error when someone try to upload other extension file like .doc. I am expecting the message ‘Only image/pdf files are allowed.’ on the form near the uploadcare widget field

Original filename saves in the file info object and it’s immutable, when you download the file it will be named with the original filename.

I think the error is here:

var input = $(this);

You need to use $uc(this) instead of $(this)

I changed $uc(this) instead of $(this), still not working

Can you reproduce that issue at Codepen.io or something so we could look into this?