Skip to main content
New Participant
November 8, 2015
Question

Read file contents from js

  • November 8, 2015
  • 1 reply
  • 2115 views

Hi I was wondering if there is there any way to read a file from the javascript side (not JSX)  of Indesign

I am trying to read a file's contents so I can upload it to AWS s3.

Any help on this matter would be much appreciated!

This topic has been closed for replies.

1 reply

Adobe Expert
November 8, 2015

> read a file from the javascript side (not JSX)  of Indesign

Can you explain what you mean? Your question is not clear.

New Participant
November 9, 2015

Lets say I have an image at the location of /tmp/image.jpg

How can I read the file's contents?

I understand from JSX it would be something like:

var file = new File("/tmp/image.jpg");
file.encoding = 'BINARY';
file.open("r");
file.read();
file.close();


However this method only works from JSX and won't work from a .js file.


So I was wondering if there's an equivalent way to do something like this from a .js file

Adobe Expert
November 9, 2015

Your outline of opening, reading, and closing a file is correct.

As to the script's file type, if you run the script from InDesign's Script panel or from the ESTK, it doesn't matter whether you use .js or .jsx. The 'x' stands for Extend, and Adobe JavaScripts are sometimes called ExtendScripts. But they're really standard JavaScripts. ExtendScript is so-called because Adone extended JavaScript with a file system and XML (and maybe something else as well).

Peter