File Upload issue

  • 1
  • Question
  • Updated 1 year ago
  • Answered
  • (Edited)
We are trying to get the base64 of an image we have uploaded by trying to get it from skuid.$M("model").data[0].Body.realBlobValue.asByteArray. With some images it works but with others the value is not there with the only field after skuid.$M("model").data[0].Body.realBlobValue being .file and it returns a value that looks like a filepath ": "/tmp/bvf/blob2885374293920319543.bvf". We would just like a little background on where to go or what to do so that we can consistently grab the base64 of the image that is uploaded
Photo of Spencer Ince

Spencer Ince

  • 90 Points 75 badge 2x thumb

Posted 1 year ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Pablo has the answer:

A little adjustment, It seems that depending of the filetype the body object is different. so for HTML files the base64 is not in .realBlobValue.asByteArray  is in .asByteArray

var field = arguments[0];var value = arguments[1];
$=skuid.$;
var Base64content;
if(value.realBlobValue!==undefined){
    Base64content=value.realBlobValue.asByteArray;}
else{
     Base64content=value.asByteArray;
}
var contenttype=field.row.ContentType;
var show="<iframe src=\"data:"+contenttype+";base64,"+Base64content+"\"></iframe>";
skuid.ui.fieldRenderers['TEXT'][field.mode](field,'');//empty
var iframe = $( '<iframe>' ).addClass('previewiframe').attr('src','data:'+contenttype+';base64,'+Base64content+'').appendTo(field.element.find('div'));
See the full thread here: https://community.skuid.com/skuid/topics/embed-attached-html-file