Html5 canvas SS2.0从html画布检索图像对象并保存到文件柜

Html5 canvas SS2.0从html画布检索图像对象并保存到文件柜,html5-canvas,netsuite,suitescript2.0,Html5 Canvas,Netsuite,Suitescript2.0,我目前正在尝试使用一些脚本从文件柜中获取图像,将url推送到HTML画布,检索宽度/高度(插入自定义字段并重新调整原始图像的大小) 在客户端脚本中,上面的代码是正常的-没有问题 然而,我想知道的是 如何在没有用户交互的情况下,将已调整大小的图像作为文件对象(N/File)抓取并保存到文件柜中 是否有一种从服务器端上下文使用HTML画布的方法 对于#1,这似乎很困难,因为N/文件模块对ClientScript不可用,所以可能需要推送到SuiteLet 到目前为止,我的一些代码 var canvas

我目前正在尝试使用一些脚本从文件柜中获取图像,将url推送到HTML画布,检索宽度/高度(插入自定义字段并重新调整原始图像的大小)

在客户端脚本中,上面的代码是正常的-没有问题

然而,我想知道的是

  • 如何在没有用户交互的情况下,将已调整大小的图像作为文件对象(N/File)抓取并保存到文件柜中

  • 是否有一种从服务器端上下文使用HTML画布的方法

  • 对于#1,这似乎很困难,因为N/文件模块对ClientScript不可用,所以可能需要推送到SuiteLet

    到目前为止,我的一些代码

    var canvas = document.getElementById("canvas");
    var ctx = canvas.getContext("2d");
    var img = new Image();
    
    img.onload = function () {
    
    // set size proportional to image
    canvas.height = canvas.width * (img.height / img.width);
    
    // step 1 - resize to 50%
    var oc = document.createElement('canvas'),
    octx = oc.getContext('2d');
    
    oc.width = img.width * 0.5;
    oc.height = img.height * 0.5;
    octx.drawImage(img, 0, 0, oc.width, oc.height);
    
    // step 2
    octx.drawImage(oc, 0, 0, oc.width * 0.5, oc.height * 0.5);
    
    // step 3, resize to final size
    ctx.drawImage(oc, 0, 0, oc.width * 0.5, oc.height * 0.5, 0, 0, canvas.width, canvas.height);
    
    var imageContent = canvas.toDataURL('image/png');
    var decodedContent = btoa(imageContent);
    
    scriptContext.currentRecord.setValue({fieldId:'custitem_image1_width', value: img.width})
    scriptContext.currentRecord.setValue({fieldId:'custitem_image1_height', value: img.height})
    
    
    img.src = scriptContext.currentRecord.getValue({fieldId:'custitem_image1_thumb_url'})
    
    上面的代码目前正在CSS pageInit中运行,我有一个单独的UES beforeLoad脚本,创建一个INLINEHTML字段
    custpage\u htmlcanvas

    var fileObj = file.create({
    name: 'test.txt',
    fileType: file.Type.PLAINTEXT,
    contents: 'Hello World\nHello World',
    description: 'This is a plain text file.',
    encoding: file.Encoding.UTF8,
    folder: 30,
    isOnline: true
    });
    

    使用suitescript 2.o中的文件模块,然后在filecabinet中创建一个文件。

    我尝试了此操作,但要么出现意外错误,要么在解码base64后得到一个空白文件。不太确定如何获取原始“内容”从canvas.img转换到文件中。你知道怎么做吗?我当前有一个base64字符串,在尝试在NSI中创建文件时遇到意外错误,最后使用了外部图像处理API…非常好。