chungchunwang/Budibase-File-Repeater

Json.parse map is not a function

Closed this issue · 16 comments

Hi, firstly, i would like to thank you for this plugin.

Howover, im facing a little problem using the plugin to show the image generated by the budibase file upload plugin

image

This is my implementation, I wonder if i did any mistakes here
image

Hi! Could you show me what is contained in the data you are providing ({New Repeater.workorder.attachments})?

Perhaps the problem could be due to the encoding protection feature I added in a recent update - it basically adds an extra character to the beginning and end of the encoded JSON to prevent a bug in Budibase. Make sure the feature is enabled for both your file upload plugins and the file repeater plugins.

Also, try to remove both plugins from your system and install the latest versions. Additionally, clear existing serialized files, as there have been breaking changes in serialization formats between older versions and the current version (This won't happen in the future, it was just because I realizes there was some bugs after I released the plugin.)

I have updated to the latest plugins version
image

Hi, there is now a new error after updating to the latest plugin versions

image

this is the content of the attachments

{"name":"Screenshot 2022-11-27 230222.png","type":"image/png","size":1731,"link":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeoAAAGOCAYAAABYCEB2AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAED0AABA9AUORddcAAAZYSURBVHhe7dWhAcAwDMCwdP+/G9ySHWEgEZ/gs7t3AICk7y8AEGTUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEG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m1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAEGbUABBm1AAQZtQAkDXzAI6bBvp1dRirAAAAAElFTkSuQmCC"}

Hi! The issue is caused by this: Budibase/budibase#8826. There should be square brackets around the contents, as such:
[The contents you provided above.]

However, it seems that Budibase interprets the square brackets as part of the SQL request and does not store them in the DB.
In the new version the encoding protection feature circumvents this. Make sure the feature is selected for both your Upload and Repeater components. Unfortunately, this means your existing stored files will not work anymore - if you open them up in this mode there will be an error. New files uploaded with this mode selected should be able to be opened.

Hopefully this solve your issue! If not, I'll be willing to help further.

I doubled check the settings from both plugins and try to recreate a new attachment and the error still persists. What other info or logs i could provide in this case?

Ps. I am using postgres as my database

image

image

Could you send me the data for the recreated file attachment?

{"name":"Screenshot 2022-11-27 230222.png","type":"image/png","size":1731,"link":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeoAAAGOCAYAAABYCEB2AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAED0AABA9AUORddcAAAZYSURBVHhe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CC"}

this is the recreated file

Weird, the square brackets are still being removed. Try clearing cache, then recreate another file attachment and test that one. Perhaps an older version of the plugin got cached causing new changes to not work it. Check if that works, and if not, could you send me the data for that? I'll look into it further tomorrow.

its just a random screenshot taken with the windows snipping tool.

I also realized that all square bracket of the fields is stripped off in the database
image

  1. I tried to manually add in the square brackets to the attachments text field but it will get removed once its saved. I suppose that is postgres issue?
  1. I tried to add square brackets using the sql statements and the error becomes the original error.
    TypeError: JSON.Parse(...)map is not a function

in the network tabs, the return result for the attachments is

"[{\"name\":\"WhatsApp Image 2022-11-09 at 10.13.42 PM (1).jpeg\",\"type\": ......
  1. The data without square brackets still returns the error
SyntaxError: Unexpected non-whitespace character after JSON at position 6

Hi! By clearing browser cache I mean this: https://support.google.com/accounts/answer/32050?hl=en&co=GENIE.Platform%3DDesktop. I just wanted to make sure the browser was not inadvertently running a cached older version of the plugin, which seemed to occur every so often when I was testing. If this is the case, you may be running an older, bugged version of the application.
Alternatively, if you can't clear the cache, just try Budibase on another device or browser that you have not used the plugin with yet.

Regarding

I tried to manually add in the square brackets to the attachments text field but it will get removed once its saved. I suppose that is postgres issue?

From what I can tell it's a Budibase issue - they interpret the brackets as part of the request syntax instead of as part of the data.

The encoding protection feature stops this by adding a period to the start and the end of the string - if you wish to restore the previous files you uploaded try manually adding both square brackets and periods like so .[original data goes here].

So, for what to do - make sure to try clearing the cache and make sure encoding protection is enabled for both the plugins - then upload a new file to see if it works.

Hi, i have tried creating the attachment and displaying attachment with the following methods:

  1. clearing the cache
  2. using another browser (firefox, chrome)
  3. open incognito mode
  4. Mobile (edge browser)

All shows the same error

Hi! I can't seem to recreate the problem on my end. I booted up a postgresSQL DB and built the default CRUD pages for a table called Files, which contains 2 text columns- Name and File. I then edited them to include the plugin, and they seem to work, as you can see in the video I linked below.

postgres-file-plugin.mp4

This leads me to believe that your plugin is still stuck on an older version, though I do not know how. Perhaps try reinstalling everything - completely deleting the plugins, clearing all instances of the plugins in your app, clearing cache, and then re-adding everything. This may be a hassle, but it's the only solution I can think of.

If this persists being an issue, perhaps file a bug report on Budibase's end about plugins not updating correctly?

Additionally, here is the export for the app I demonstrated in the video above.
My app2-export-1669732325837.tar.gz
Try testing this as well.

I will try to help further if these solutions don't work, though it may be hard to find a resolution if I can't recreate the issue on my end.

P.S. Sorry for the late reply, it may be like this for a couple of days, as I am a bit sick.

Also, perhaps try to do what I did in the video - create an empty project with a CRUD table to test the plugin.

Additionally, if it is possible, could you give me a follow and star the repo? I am a student and these things help me build my resume.

Also, perhaps try to do what I did in the video - create an empty project with a CRUD table to test the plugin.

Additionally, if it is possible, could you give me a follow and star the two repos? I am a student and these things help me build my resume.

Ok, I'll close this off for now since its been a couple of days and I can't recreate the issue. Feel free to reopen it to follow up on the problem.

not sure what i did differently this time, it is working now! Many thanks for this wonderful plugin