Support Topics Documentation Slack YouTube Blog

How to set relation to filereference


(SnakeEyes) #1

Hello
I am using Java/Android sdk.
The table I have is using dynamic schema creation so initially table does not have column or does not even exist
I save the file using the files api and get the link.
I set the link to the table data.
Then I use the data api to save the map.

The issue is that the column is created as a string not as a file reference.

How can I make it so it creates the column as a file reference ? I can’t see examples of that

Thank you


(Mark Piller) #2

Unfortunately, this is one of the shortfalls of the dynamic schema definition. For “file reference” you would need to define the column manually or using the console API.

Regards,
Mark


(SnakeEyes) #3

Oh ok. Thank you for pointing this out. I will work around it then


(SnakeEyes) #4

Hi Mark,
So I created the table definition with file reference.
Then I execute the following code

BackendlessFile bkFile = Backendless.Files.upload( jsonFile,remotePath,true);
restaurentHM.put(“JSONfile”, bkFile.getFileURL());
Map ret1 = Backendless.Data.of(“Restaurant”).save(restaurentHM);

It ends up putting the file reference in the table as a clickable file name in the console. Good. Now when I log in to the console and click on the file name reference in that table row, it just takes me to the main dashboard!. However if I remove the relatioship in the console and manually choose the file reference through console, then clicking on file name will take me to file in the Files section.

What am I doing wrong? Why is the behaviour different?
Thank you


(Mark Piller) #5

This might be a bug in console. Could you please check if the data (the URL) is returned properly when you fetch it with the API? You can do that using the REST console built into the Data screen.


(SnakeEyes) #6

Hi Mark,
Yes the returned URL String when I do a GET from console is correct.


(Mark Piller) #7

This confirms it is a problem in the console itself and not in the API layer of the service.


(Stanislaw Grin) #8

Hi @snakeeyes,
could you please provide me with info on:

  • which browser do you use
  • what is the extension of the file (it would be nice if you provide me with that file if it’s possible)
  • do you see this behavior with any file or with particular one?
  • also can you please check if the same behavior occurs when you save object with REST Console (in console UI)?

Did you changed the type of you File Reference column from another one (say created String column first and after that changed to File Reference it), or created directly File Reference column?

I’m asking about this because I tried to reproduce your problem and did not have success in it.

Regards,
Stan


(SnakeEyes) #9

Hello Stanislaw,

  • I used Mozilla with it but I doubt it has impact due to the rest of the info below.
  • The file extension is .JSON. I can send it by email if you want. It is less than 100 KB.
  • I see the same behaviour with any json file I upload
  • If set the relation through by clicking on the + button in the row ( and choose the file from the Files section), then the behaviour is correct. Not sure how to do it from the REST control API.

Yes when I first created the table it treated the column as String. Then I changed it to be file reference then I uploaded data again. See screenshot below:
Backendless

The first one is done through upload from the java code. Clicking on it will take you to main dashboard.
The second one is when I reset the relationship through the plus button. When I click on it, it takes me to the Files section where the file is.

Hope this helps


(Stanislaw Grin) #10

Thank you for the information. That helped me to find out the issue and we’ve already fixed it, so with next release this fix will be available for you.


(SnakeEyes) #11

Perfect! Thank you very much