Preview:
public class NW_AttachFileHelper
{
    public static void UploadFileBase64(str _base64, TableId _refTableId, RecId _refRecId, str _filename,str _TypeId = 'File', str _fileExtension = "pdf")
    {
        DocuRef Ref;
        DocuValue Value;
        //System.Byte[]    reportBytes = new System.Byte[0]();
        //reportBytes = System.Convert::FromBase64String(_base64);
        //System.IO.Stream      stream = new System.IO.MemoryStream(reportBytes);
        //DocumentManagement::attachFile(_refTableId, _refRecId, curExt(),  DocuType::typeFile(),stream,
        //    System.IO.Path::GetFileName(_fileName),
        //    System.Web.MimeMapping::GetMimeMapping(_fileName),
        //    System.IO.Path::GetFileNameWithoutExtension(_fileName));

             //DocumentManagement::attachFile(
             //   _tableId,
             //   _recId,
             //   _dataAreaId,
             //   DocuType::typeFile(),
             //   memoryStream,
             //   System.IO.Path::GetFileName(_fileName),
             //   System.Web.MimeMapping::GetMimeMapping(_fileName),
             //   System.IO.Path::GetFileNameWithoutExtension(_fileName));
        str Path, filePath;
        BinData binData;
        filePath = System.IO.Path::GetTempPath(); //Get temp path
        Path = filePath + _filename + '.' + _fileExtension;

        ttsBegin;
        Value.clear();
        binData = new binData();
        Value.File = BinData::loadFromBase64(_base64);
        Value.Name = _filename;
        Value.FileName = _filename;
        Value.FileType = _fileExtension;
        Value.OriginalFileName = _filename +"." + _fileExtension;
       // Value.Path = Path;
        Value.insert(); // insert into DB
        if (Value.RecId)
        {
            Ref.clear();
            Ref.RefRecId = _refRecid;
            Ref.RefTableId = _refTableId;
            Ref.RefCompanyId = curext();
            Ref.Name = _filename;
            Ref.TypeId = _TypeId;
            Ref.ValueRecId = Value.RecId;

            Ref.insert();
        }
        ttsCommit;
    }

}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter