Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
11

Script for downloading a file

Participant ,
Jan 19, 2024 Jan 19, 2024

Is it possible to create a jsx script to download a file?

TOPICS
Scripting , SDK
808
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Jan 19, 2024 Jan 19, 2024

In ExtendScript you can use Kris Coppieters's 

https://coppieters.nz/?p=720

 

In UXP you can use one of the standard modules.

Translate
Participant , Jan 28, 2024 Jan 28, 2024

I ended upp using this approach. My plugin is writte in angular.js. 

I use this .js code to download the file:

 

fac.downloadFile = function (url) {

var deferred = $q.defer();
return $http({
method: 'GET',
url: url,
responseType:'arraybuffer',
headers: {
'Content-Type': undefined
},
transformResponse: function (data) {
return data;
}
});
}

 

The I use the following code in jsx to save the file to disk:

 

function cargo_WriteFileToDisc(object) {
var string = unescape(object);
var errorString = "";
var docObject = JSON.

...
Translate
Community Expert ,
Jan 19, 2024 Jan 19, 2024

In ExtendScript you can use Kris Coppieters's 

https://coppieters.nz/?p=720

 

In UXP you can use one of the standard modules.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2024 Jan 19, 2024

In addition to Peter's excellent suggestions, you can also write a curl string command and execute it via VB or AS depending on OS. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 20, 2024 Jan 20, 2024

Another option for windows is Autohotkey script

One line code.

Example:

UrlDownloadToFile, http://someorg.org/archive.zip, C:\SomeOrg's Archive.zip

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2024 Jan 23, 2024

Another option could be to create an invisible CEP extension and then send CSXS event from jsx to js for downloading the file.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 28, 2024 Jan 28, 2024
LATEST

I ended upp using this approach. My plugin is writte in angular.js. 

I use this .js code to download the file:

 

fac.downloadFile = function (url) {

var deferred = $q.defer();
return $http({
method: 'GET',
url: url,
responseType:'arraybuffer',
headers: {
'Content-Type': undefined
},
transformResponse: function (data) {
return data;
}
});
}

 

The I use the following code in jsx to save the file to disk:

 

function cargo_WriteFileToDisc(object) {
var string = unescape(object);
var errorString = "";
var docObject = JSON.parse(string);
var doc = app.activeDocument;
var imagePath = File(doc.filePath + "/" + docObject.filename);

if (docObject.imageData != null)
{
imagePath.open("w");
imagePath.encoding = "BINARY";
imagePath.write(docObject.imageData);
imagePath.close();
}
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines