从 Photoshop 将文件发送到 API

Send a file to an API from Photoshop

我需要将当前在 photoshop 中打开的活动文档发送给需要参数中文件的 JS 函数。

我试过像这样获取文件的路径:

csInterface.evalScript('app.documents[0].fullName.parent.fsName.toString()',function(result){
    csInterface.evalScript('app.documents[0].name', function(res) {
      var response = result+"/"+res;
      var path = response.replace(/\/g, '/');
      console.log(path);
      var file = window.cep.fs.readFile(path);
      console.log(file);
      //projectCreateDownloadToken(file.data);
    });

然后使用 window.cep.fs.readFile 从路径中获取文件,但它只获取数据而不获取文件。

也许我需要使用

 var arg = 'file=@'+path;
  var url ="your_server_url ";
  console.log(window.cep.process.createProcess('/usr/bin/curl','--form',arg,url));

但我正在寻找其他解决方案。感谢您的帮助!

我能够使用此代码做到这一点

csInterface.evalScript('app.documents[0].fullName.fsName', function(res) {
      let fileInBase64 = window.cep.fs.readFile(res, cep.encoding.Base64);
      let fileName =  res.split('\').pop().split('/').pop();
      urltoFile('data:image/png;base64,'+fileInBase64.data, fileName)
      .then(function(file){
        //do what you want with the file
      });
    });
  }, false);