uploadcare / react-widget

Uploadcare React Widget
MIT License
85 stars 18 forks source link

passing metadata object to react uploadcare widget #355

Closed ehudmi closed 2 years ago

ehudmi commented 2 years ago

Question

I'm trying to pass the widget metadata info to set on all files to be uploaded with the widget and I'm getting: "Option "metadata" is expected to be an object. Instead got: string " I was trying basically to pass metadata as: metadata = { {userId: authState.userId, projectId: projectName} }; within the

nd0ut commented 2 years ago

Hey @ehudmi,

passing metadata to the react-widget as a prop isn't implemented yet. It will be released soon.

As a workaround you can use global variables like UPLOADCARE_METADATA or UPLOADCARE_METADATA_CALLBACK

ehudmi commented 2 years ago

Thanks for the response - my problem was apparently due to not formatting the metadata properly.

metadata={JSON.stringify({ userId: authState.userId, projectId: projectName, })}

this worked perfectly for me - I was importing the widget into another component and passing the values for userId and projectId dynamically from the hosting component

ehudmi commented 2 years ago

I do have another question though - is it possible to limit number of uploadable files using the validators? Not to let a user upload more than 3 files...

nd0ut commented 2 years ago

I do have another question though - is it possible to limit number of uploadable files using the validators? Not to let a user upload more than 3 files...

Yeah, it's possible using multipleMax option. See https://uploadcare.com/docs/uploads/file-uploader-options/#option-multiple-max

nd0ut commented 2 years ago

Thanks for the response - my problem was apparently due to not formatting the metadata properly.

metadata={JSON.stringify({ userId: authState.userId, projectId: projectName, })}

this worked perfectly for me - I was importing the widget into another component and passing the values for userId and projectId dynamically from the hosting component

It was kinda undocumented feature. It won't work in v2.3.0 anymore. So you will need to use metadata = { {userId: authState.userId, projectId: projectName} }; as you tried before.

ehudmi commented 2 years ago

I do have another question though - is it possible to limit number of uploadable files using the validators? Not to let a user upload more than 3 files...

Yeah, it's possible using multipleMax option. See https://uploadcare.com/docs/uploads/file-uploader-options/#option-multiple-max

Great - thanks...it looks awesome...