[4.2] - rbf_createRecord() file upload field value

Posted by IramK on 09-Aug-2016 11:23

Hello,

I have a form that has a File Upload field. Is it possible to create a record and set the field upload field value using client side API i.e. rbf_createRecord()?

Cheers.

Iram

All Replies

Posted by Chandrasekhar Gontla on 09-Aug-2016 12:02

Hi Iram,

It is not possible to set value for file upload field using rbf_createRecord() api.

Thanks and Regards,

Chandu.

Posted by IramK on 09-Aug-2016 13:42

Hello Chandu,

Thanks for your reply. So if I have the B64 encoded value of a file, how can I set the field value for a file upload field using the rbv_api.setBinaryFieldValue() function from client-side? Also is there a field in rollbase that does not have a limit on the number of characters? Textarea field in general only stores a maximum of 8K characters. Please let me know.

Thanks.
Iram

Posted by Shiva Duriseati on 10-Aug-2016 01:16

Hi Iram,

rbv_api.setBinaryFieldValue() is a  server-side APIs which can be used only in formulas, formula fields, and triggers. And cannot be used from client side.

You could set the value of file using rbv_api.createRecord(objName, arr) with some additional tweak in the code.If you want I can share you the details.

Regards,

Shiva

Posted by IramK on 10-Aug-2016 03:19

Hi [mention:efd18cd3210243c3a2645cbe9409d974:e9ed411860ed4f2ba0265705b8793d05] ,

Yes please do share the code for this. Its quite interesting to know that we can use rbv_api.createRecord(). Would it just be the case of supplying the file upload field with the base64 encoded value of the string?

Also now that you suggested this idea, could you tell me if we can run a trigger from client-side by supplying the B64 encoded value of the file that calls this server-side create record function and uses that B64 file value to create the record?

Cheers.

Iram

Posted by Shiva Duriseati on 10-Aug-2016 04:23

Hi Iram,

As you mentioned just supplying the base64 value to the createRecord will not resolve the problem we need to use setBinaryFieldValue API.

Example:

Lets say we have two objects 'A' and 'B'

Object A has file upload field and assume that we need to read that file and store it in Object 'B' on creation of every record in 'A' create an object script trigger which will read b64 from uploaded file and set that value to a text field in object 'B'

In object 'B' create a dummy text field to store b46 value and also a trigger of type object script which will read binary data from dummy text field and set that value to file upload field in object B.

Following are the triggers(Object script) written in both A and B respectively

Trigger in 'A'

var binaryData=rbv_api.getBinaryData("A", {!id}, "Upload_File");

rbv_api.createRecord("B", {'name':'{!name#text}','Dummy_Text_':binaryData});

Trigger in 'B

var binaryValue=rbv_api.getFieldValue('B', {!id}, 'Dummy_Text_');

if(binaryValue!==null){

rbv_api.setBinaryFieldValue('B', {!id}, 'Upload', binaryValue, "image/jpg", "Somefile.jpg");

}

Note: You can make additional changes to trigger B for setting file of any time and applicable name(I have hardcoded file name here.)

Attaching app.xml for you reference.

For your second point calling server side API from client side is not possible.

[View:/cfs-file/__key/communityserver-discussions-components-files/25/CreateFile_5F00_v2.xml:320:240]

Regards,

Shiva

Posted by IramK on 10-Aug-2016 05:16

Hello [mention:efd18cd3210243c3a2645cbe9409d974:e9ed411860ed4f2ba0265705b8793d05] ,

Thanks for your answer. I exactly had the same idea in my mind which is why I asked the question above relating to the fact that will there be a possibility of storing this B64 value in a field that has no limit on characters?

You suggested a text field but I'm sure that a file that has a size of 10 MB would definitely have more characters than what can be stored in a text field, correct? So with regards to this approach, I'm sure this will work but what else can we use instead of that text field?

Cheers.

Iram

Posted by Shiva Duriseati on 11-Aug-2016 02:09

Hi Iram,

With the above approach I tried to upload an xml with size 97MB(Since at present we are limiting file upload to 97MB) and its working fine.(I have used text field to store binary value)

(or)

Since you are in Private Cloud, you can add java classes to be exposed to Rollbase javascript. Then you can call these Java methods from Object Script to set the binary data to file upload field.

See CustomClassFilter documentation here -documentation.progress.com/.../index.html

Regards,

Shiva

Posted by IramK on 22-Aug-2016 10:40

Hello [mention:efd18cd3210243c3a2645cbe9409d974:e9ed411860ed4f2ba0265705b8793d05] ,

Thanks for your answer. I tried using your approach but I am coming down to the same issue of not being able to transport the B64 value of the file to server side. I cannot physically upload a file and get the B64 value of that just after create (since its all happening in the background using rbf_createRecord) but since rbf_createRecord doesn't support setting the file upload field value, its not working out as such. Could there be another approach to this using the same principle?

Also could you provide more details on the 2nd option please along with examples?

Cheers.

Iram

Posted by Shiva Duriseati on 22-Aug-2016 11:24

Hi Iram,

"not being able to transport the B64 value of the file to server side" as we discussed in earlier approach set this B64 to text field using createRecord API after record is created with binary value,then this value could be read by object script trigger using getFieldValue api once we have binary value then we can set this binary value to file upload field for the current record.

Following threads have examples on using CustomClassFilters

community.progress.com/.../22626

community.progress.com/.../25288

[mention:19aa761d6eff491bb43da3a9faf25681:e9ed411860ed4f2ba0265705b8793d05] Please create a support ticket , I can help you with this.

Regards,

Shiva

Posted by IramK on 22-Aug-2016 11:34

Hello [mention:efd18cd3210243c3a2645cbe9409d974:e9ed411860ed4f2ba0265705b8793d05] ,

I have created a support case: 00360511. Shall speak to you soon.

Cheers.

Iram

Posted by Shiva Duriseati on 22-Aug-2016 11:37

Thank you Iram,

Posted by IramK on 15-May-2017 09:17

Hi Shiva,

How can we get the MIME type from the encoded binary value in this sample app you have attached?

Cheers.

Iram

Posted by Shiva Duriseati on 16-May-2017 05:40

Hi Iram,

Unfortunately b64 string may contain any unpredictable string from which retrieving MIME type is not possible.

One  workaround is you can determine the MIME type at the time of uploading the file,setting it to any field in another object and use that string before setting the file in another object.

Regards,

Shiva

This thread is closed