Highlighted

Downlaod From Link In Adobe Air To Documents Folder Automatically Without Pop-up Dialog...

New Here ,
Sep 19, 2014

Copy link to clipboard

Copied

Hi,

Can someone help me figure out or provide some sample code on the method I would need to take to download a file from the internet and automatically have Adobe Air save that file somewhere on my computer (probably Documents folder) and also not pop-up that Save To dialog box?

I'm downloading a file just fine now, but the main issue is that the pop-up window comes up and ask me where do I want to save the file. I do not need it to do that. I want it to automatically save to a location on my computer.

Thanks guys

A long time ago when I was first getting into AIR, I created a downloader application to do basically what you are asking help for. Below is code for the part that you need to download and save a file. If the file you are downloading is dynamically generated or has special reference links, you will have to do something fancy for knowing the file extension to know what the full file name should be. I just tested the code for downloading an image and the HTML file for the FileStream ASDoc

import flash.events.Event;

import flash.filesystem.File;

import flash.filesystem.FileMode;

import flash.filesystem.FileStream;

import flash.net.URLRequest;

import flash.net.URLStream;

import flash.utils.ByteArray;

var documentsDirectory:File = File.documentsDirectory;// active user documents directory

var fileName:String;

var fileToSave:File;

var fileStream:FileStream;

var fileData:ByteArray;

var urlRequest:URLRequest = new URLRequest("http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html");

var urlStream:URLStream = new URLStream();

urlStream.addEventListener(Event.COMPLETE, onDownloadComplete);

urlStream.load(urlRequest);

function onDownloadComplete(e:Event):void {

  // get the index position of the last forward slash in the file path

  var startIndex:int = urlRequest.url.lastIndexOf("/") + 1;

  // set fileName equal to url string starting after the last forward slash

  fileName = urlRequest.url.substring(startIndex);

  // create a new File object at the user Directory folder with the correct file

  fileToSave = documentsDirectory.resolvePath(fileName);name

  // create ByteArray to store data downloaded from URLLoader

  fileData = new ByteArray();

  // write the data from URLLoader to ByteArray

  urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);

  // create FileStream to save data to File

  fileStream = new FileStream();

  // open file in a WRITE mode to save data to the File

  fileStream.open(fileToSave, FileMode.WRITE);

  // write the data to the file

  fileStream.writeBytes(fileData, 0, fileData.length);

  // close FileStream when done

  fileStream.close();

}

TOPICS
Development

Views

343

Likes

Translate

Translate

Report

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

Downlaod From Link In Adobe Air To Documents Folder Automatically Without Pop-up Dialog...

New Here ,
Sep 19, 2014

Copy link to clipboard

Copied

Hi,

Can someone help me figure out or provide some sample code on the method I would need to take to download a file from the internet and automatically have Adobe Air save that file somewhere on my computer (probably Documents folder) and also not pop-up that Save To dialog box?

I'm downloading a file just fine now, but the main issue is that the pop-up window comes up and ask me where do I want to save the file. I do not need it to do that. I want it to automatically save to a location on my computer.

Thanks guys

A long time ago when I was first getting into AIR, I created a downloader application to do basically what you are asking help for. Below is code for the part that you need to download and save a file. If the file you are downloading is dynamically generated or has special reference links, you will have to do something fancy for knowing the file extension to know what the full file name should be. I just tested the code for downloading an image and the HTML file for the FileStream ASDoc

import flash.events.Event;

import flash.filesystem.File;

import flash.filesystem.FileMode;

import flash.filesystem.FileStream;

import flash.net.URLRequest;

import flash.net.URLStream;

import flash.utils.ByteArray;

var documentsDirectory:File = File.documentsDirectory;// active user documents directory

var fileName:String;

var fileToSave:File;

var fileStream:FileStream;

var fileData:ByteArray;

var urlRequest:URLRequest = new URLRequest("http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html");

var urlStream:URLStream = new URLStream();

urlStream.addEventListener(Event.COMPLETE, onDownloadComplete);

urlStream.load(urlRequest);

function onDownloadComplete(e:Event):void {

  // get the index position of the last forward slash in the file path

  var startIndex:int = urlRequest.url.lastIndexOf("/") + 1;

  // set fileName equal to url string starting after the last forward slash

  fileName = urlRequest.url.substring(startIndex);

  // create a new File object at the user Directory folder with the correct file

  fileToSave = documentsDirectory.resolvePath(fileName);name

  // create ByteArray to store data downloaded from URLLoader

  fileData = new ByteArray();

  // write the data from URLLoader to ByteArray

  urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);

  // create FileStream to save data to File

  fileStream = new FileStream();

  // open file in a WRITE mode to save data to the File

  fileStream.open(fileToSave, FileMode.WRITE);

  // write the data to the file

  fileStream.writeBytes(fileData, 0, fileData.length);

  // close FileStream when done

  fileStream.close();

}

TOPICS
Development

Views

344

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 19, 2014 0
Contributor ,
Sep 19, 2014

Copy link to clipboard

Copied

Hmmm, what operating system and web browser do you use? You shouldn't need AIR to tell your  browser where to save a file. That ability is in most web bowsers functionality. Usually you'd find it in the options/preferences menu within your web browser. Im using safari, I just download and files always go to my downloads folder by default or anywhere I set it to go in Safaris preferences.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 19, 2014 0
New Here ,
Sep 19, 2014

Copy link to clipboard

Copied

No, I do not want to rely on what browser someone is using. I believe I read somewhere that you can use FileStream to grab a file from the internet/server, and automatically download that file to a certain location on your computer with Adobe Air. This feature I'm implementing is apart of a larger application, and that's why I need Adobe Air to automatically download the file to a location I define in the Adobe Air program.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 19, 2014 0
Contributor ,
Sep 19, 2014

Copy link to clipboard

Copied

Oh ok, if its an air file theres a script here Adobe AIR * Downloading an AIR file to the user’s computer. Not sure on other file types

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 19, 2014 0
New Here ,
Sep 19, 2014

Copy link to clipboard

Copied

I didn't try this out yet, but is that specifically only for files that end in a .air extention, or can that be used for "any" file (Ex. zips, images, tars, etc.)?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 19, 2014 0
Contributor ,
Sep 19, 2014

Copy link to clipboard

Copied

Only AIR but I'm sure google will find all sorts of extensions for others if no one here knows of or uses any

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 19, 2014 0
Engaged ,
Sep 21, 2014

Copy link to clipboard

Copied

A long time ago when I was first getting into AIR, I created a downloader application to do basically what you are asking help for. Below is code for the part that you need to download and save a file. If the file you are downloading is dynamically generated or has special reference links, you will have to do something fancy for knowing the file extension to know what the full file name should be. I just tested the code for downloading an image and the HTML file for the FileStream ASDoc

import flash.events.Event;

import flash.filesystem.File;

import flash.filesystem.FileMode;

import flash.filesystem.FileStream;

import flash.net.URLRequest;

import flash.net.URLStream;

import flash.utils.ByteArray;

var documentsDirectory:File = File.documentsDirectory;// active user documents directory

var fileName:String;

var fileToSave:File;

var fileStream:FileStream;

var fileData:ByteArray;

var urlRequest:URLRequest = new URLRequest("http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html");

var urlStream:URLStream = new URLStream();

urlStream.addEventListener(Event.COMPLETE, onDownloadComplete);

urlStream.load(urlRequest);

function onDownloadComplete(e:Event):void {

  // get the index position of the last forward slash in the file path

  var startIndex:int = urlRequest.url.lastIndexOf("/") + 1;

  // set fileName equal to url string starting after the last forward slash

  fileName = urlRequest.url.substring(startIndex);

  // create a new File object at the user Directory folder with the correct file

  fileToSave = documentsDirectory.resolvePath(fileName);name

  // create ByteArray to store data downloaded from URLLoader

  fileData = new ByteArray();

  // write the data from URLLoader to ByteArray

  urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);

  // create FileStream to save data to File

  fileStream = new FileStream();

  // open file in a WRITE mode to save data to the File

  fileStream.open(fileToSave, FileMode.WRITE);

  // write the data to the file

  fileStream.writeBytes(fileData, 0, fileData.length);

  // close FileStream when done

  fileStream.close();

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 21, 2014 0
New Here ,
Sep 21, 2014

Copy link to clipboard

Copied

Thank you

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 21, 2014 0