Javascript 从Photoshop向API发送文件

Javascript 从Photoshop向API发送文件,javascript,photoshop,Javascript,Photoshop,我需要将当前的活动文档在photoshop中打开,并将其发送给需要参数中的文件的JS函数 我尝试通过如下方式获取文件的路径: csInterface.evalScript('app.documents[0].fullName.parent.fsName.toString()',function(result){ csInterface.evalScript('app.documents[0].name', function(res) { var response = resu

我需要将当前的活动文档在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);

你说的“获取文件”是什么意思?你到底想做什么?@SergeyKritskiy我想把文件放在服务器上的photoshop中打开。所以我需要有一个javascript文件对象,其中包含Photoshop中当前的活动文档。在前两行中,您将获得PS中第一个文档所在的文件夹,然后在另一个脚本中,您将获得它的名称。。。如果你能通过
activeDocument.fullName
获得文件路径,
result+“/”+res
有什么意义?@SergeyKritskiy文件名不在全名中,他只给出文件所在的目录,所以我必须这样做才能获得文件的完整绝对路径你错了,
activeDocument.fullName
提供完整路径。在您的代码中,您只使用文件夹,因为您使用了
.parent
——因此您将向上提升一级