Adding relation between image in file storage and data table

How do I set or add relation to an image file in file storage with a column in data table programmatically without using console.

Hi @Yomade_Stephens

FILE_REF is just a string column, so you can work with it as with primitive columns.

public void saveNewPerson()
{
  HashMap person = new HashMap();
  person.put( "name", "Jack Daniels" );
  person.put( "avatar", "https://path/to/avatar.jpg" );
  
  // save object synchronously
  Map savedPerson = Backendless.Persistence.of( "Person" ).save( person );

  // save object asynchronously
  Backendless.Persistence.of( "Person" ).save( person, new AsyncCallback<Map>() {
      public void handleResponse( Map response )
      {
        // new Person instance has been saved
      }

      public void handleFault( BackendlessFault fault )
      {
        // an error has occurred, the error code can be retrieved with fault.getCode()
      }
    });
}

https://backendless.com/docs/android/data_single_object_create.html#example

Regards, Vlad

Don’t think this is related to what I need. Take an instance I uploaded an image file to backendless storage as user display image, to get the url I need to create a relation of the current user to that image file to show the image to the user as display image. Api to set relation needed if available without using console.

@Yomade_Stephens, Vlad gave you correct advice. If you store file path as a string it will be treated by backendless as a relation. Just try to store the file url and go to console, you will see it as relation.

Figured it out. Tanx guys.

Jumping on this older thread as I have a similar question. How do you get / store the file path as a string to then use in the relation?

My goal is to save a parent object and have it automatically create a relation in the Media column (FileReference) to a file that was already uploaded.

My thought process is this (but it’s not working):

  1. Confirmed the Media column is File reference
    Screen Shot 2022-07-28 at 10.55.39 AM

  2. On upload success store the uploaded file as a property in Page Data

  3. On submission, set the object relation between my parent object and the file uploaded

Through this the file gets uploaded, but it is not creating the relation with my parent object. Appreciate your help!

Hi @Max_Guilbert

Actually, the “File Ref” is not a relation, this is a regular data type like “String” and in order to update the property just set the value to the “parent” object using the “Set Object Property” block and then save it using the “Save Object in Backendless” block

Regards, Vlad

Hi Vlad - appreciate the response!

I think I’m close but it’s still not working.

  1. I’m saving the uploaded file to page data with property “uploadedFile”
    Screen Shot 2022-07-28 at 2.19.08 PM

  2. Then adding it to the parent object when saving the Object in backendless.

anything look off? I’m trying to save the File in the Media column so that it references the File in the database.

seems like it should work, do you have any errors?

You can open the browser dev tool and then check the Network section to see what exactly goes to the server

No errors. After uploading the image, then hitting submit for the Poll question I see the file URL as part of the Request Payload, but under preview it has Media = ‘null’.


Figured it out!

I had selected the option “Multiple Files” on the file upload, so it was storing them in a list(?).

Once I unchecked that box in the FE, it passed the fileURL as expected.

appreciate your help :raised_hands:

1 Like