Skip to main content
Participant
November 18, 2016
Question

Photoshop Scripting: How to convert psd image in base64 in jsx to send it on server

  • November 18, 2016
  • 1 reply
  • 1785 views

I am working on a photoshop plugin. I want to convert the photoshop psd file in Base64 so that I can send it on my server. But this following code is not running. It gives EvalScript Error.

<pre>

var filepath = app.activeDocument.path + '/' + name + '.png';

  //get file buffer
  var f= new File(filepath);
  f.open();
  f.encoding = 'BINARY';
  var buffer = f.read(f.length);
  f.close();

  //file buffer to base64
  var base64 = base64Encode(buffer);

  return base64;

</pre>

This topic has been closed for replies.

1 reply

Jarda Bereza
Inspiring
November 25, 2016

I guess base64Encode() function not exists. I don't see your definition in your code and Photoshop script core is a bit old and think it doesn't has built-in function for that.

You could google old school method for base64 conversion. Something like: Base64.js/base64.js at master · davidchambers/Base64.js · GitHub  but you should do some modifications.

Or If you have HTML panel. Then you can send data to javascript panel, then use native built-in Chrome function for conversion (.atob) and then send data back.

For sending you also could use HTML panel and make some Ajax request or something. Or use "Socket" class in JSX (TCP/IP connection)

Or If you have public IP or If you want use it in LAN then you can use Connection SDK.