Using Widget get the uploaded file name

I must be being ‘thick’ :slight_smile: have the widget opening using a custom button - that works, the widget uploads the files, that works, but I just cannot see/get how to get the new file name.

What I have is:

document.querySelector(’#frm-profile-setup [data-id=“photoURL”]’).addEventListener(‘click’,function(){
uploadcare.openDialog(null,{
publicKey:‘XXXXXXXXXXX’,
imagesOnly:true,
crop:‘300x300’
})
})

Now how do I get the ‘new’ file name when the upload is complete, I need this to update a database

I am 100% sure it’s very simple, so as said I am being ‘thick’ - Oh I’m not using jQuery

Hi @parrott.russell,

uploadcareOpenDialog returns a dialog instance which has the “done” method that returns a file promise when a file is uploaded. Resolving the file promise, you can obtain file information that includes the original file name and some other file-related data. Try this code snippet

const dialog = uploadcare.openDialog(null, '', {})
dialog.done(res => {
  res.done(fileInfo => {
    console.log(fileInfo.name);
  });
});

Hope that helps.

See, told you I was being thick :slight_smile: - perfect and done thanks

1 Like