Downloading image files from the server and saving them on local disk

Hello,
In an AIR app. i want to download number of image files,i have paths
in an array.I am looping through the array and using URLLoader.Format
is BINARY,now on the complete event of one file i dont know how to
store the file on the disk as exactly which file has dispatched the
event is not known.Please point out if my approach is incorrect or if
any other ideas -plz share.

Try the following:
var imgURLs:Array = new Array();
imgURLs[0] = "http://www.adobe.com/ubi/globalnav/include/adobe-lq.png";
imgURLs[1] = "http://www.adobe.com/images/shared/download_buttons/get_adobe_air.png";
var urlRequests:Array = new Array();
var urlLoaders:Array = [];
for (var i:int = 0; i < imgURLs.length; i++)
    loadURL(i);
function loadURL(i:int):void
    var urlReq:URLRequest = new URLRequest(imgURLs[i]);
    urlRequests[i] = urlReq;
    var urlLoader:URLLoader = new URLLoader(urlReq);
    urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
    urlLoader.addEventListener(Event.COMPLETE,                
                function (event:Event):void
                    var path:String = urlReq.url;
                    var urlLoader:URLLoader = event.target as URLLoader;
                    saveFileData(path, urlLoader.data);
function saveFileData(path:String, data:ByteArray):void
    trace(path, data.bytesAvailable);
    // I'll let you write the code to save the data to a file path, based on the URL.
You could also create a class that includes the event handler function and includes the code for loading the data. Then create a new instance of that class for each URL.

Similar Messages

  • HT1473 i have downloaded some songs from the internet and saved it on my desktop. how do i transfer those songs to itunes?

    i have downloaded some songs from the internet and saved it on my desktop. but i do not know how to import the songs from that folder to itunes.

    Just drag the song(s) to iTunes, if they are one of these formats (wav, m4a, mp3, mp4, wma etc) and they will appear under Music library.
    If you have lots of music files, put them in a folder and go iTunes menu FILE, Add folder to library..... to add this folder at one go.

  • Is there a way to open Excell file from the server and display in the UI and save it back on to the

    Hello there,
    Is there a way to open Excell file from the server and display in the UI and save it back on to the server? (like showing xell file as a datagrid - add rows, columns etc.)

    Hi Mike,
    Welcome you to the forum.
    You may try:
    SELECT * FROM MyDBNameHere.dbo.OUSR T0
    Thanks,
    Gordon

  • How to download a file from the net and save it into .txt format in a datab

    Can some one show me a tutorial on how to download a file from the net and save it into .txt format in a database?
    Thank you,

    http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html

  • Download files from the URL and store them in the table

    Hello,
    I want to download files from the URL and want to store them in the table.
    Can I do it using sql/pl-sql.
    Please help me on this.
    Thanks,
    Rajendra Yadav

    Never tried it before...
    Is this what you are talking about?
    http://www.oracle-base.com/articles/10g/file-upload-download-procedures-10g.php
    Cheers,
    Manik.

  • Download ECS files from the server

    Currently we have production on Oracle Application Server Integration B2B, Release 10.1.2, Build B2B_10.1.2.4.0_GENERIC_100714.
    Is there a way to download current ECS files from the prod server?
    Regards,
    Suneel Jakka

    Download ECS files from the server
    Regards,
    Anuj

  • How use PHP to read image files from a folder and display them in Flex 3 tilelist.

    Hello. I need help on displaying images from a folder dynamically using PHP and display it on FLEX 3 TileList. Im currently able to read the image files from the folder but i don't know how to display them in the TileList. This is my current code
    PHP :
    PHP Code:
    <?php
    //Open images directory
    $imglist = '';
    $dir = dir("C:\Documents and Settings\april09mpsip\My Documents\Flex Builder 3\PHPTEST\src\Assets\images");
    //List files in images directory
    while (($file = $dir->read()) !== false)
    if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
    echo "filename: " . $file . "\n";
    $dir->close();
    ?>
    FLEX 3 :
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="pic.send();">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    import mx.rpc.events.FaultEvent;
    import mx.events.ItemClickEvent;
    import mx.rpc.events.ResultEvent;
    public var image:Object;
    private function resultHandler(event:ResultEvent):void
    image = (event.result);
    ta1.text = String(event.result);
    private function faultHandler(event:FaultEvent):void
    ta1.text = "Fault Response from HTTPService call:\n ";
    ]]>
    </mx:Script>
    <mx:TileList x="31" y="22" initialize="init();" dataProvider = "{image}" width="630" height="149"/>
    <mx:String id="phpPicture">http://localhost/php/Picture.php</mx:String>
    <mx:HTTPService id="pic" url="{phpPicture}" method="POST"
    result="{resultHandler(event)}" fault="{faultHandler(event)}"/>
    <mx:TextArea x="136" y="325" width="182" height="221" id="ta1" editable="false"/>
    <mx:Label x="136" y="297" text="List of files in the folder" width="182" height="20" fontWeight="bold" fontSize="13"/>
    </mx:Application>
    Thanks. Need help as soon as possbile. URGENT.

    i have made some changes, in the php part too, and following is the resulting code( i tried it, and found that it works.):
    PHP Code:
    <?php
    echo '<?xml version="1.0" encoding="utf-8"?>';
    ?>
    <root>
    <images>
    <?php
    //Open images directory
    $dir = dir("images");
    //List files in images directory
    while (($file = $dir->read()) !== false)
    if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
    echo "<image>" . $file . "</image>"; // i expect you to use the relative path in $dir, not C:\..........
    //$dir->close();
    ?>
    </images>
    </root>
    Flex Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    creationComplete="callPHP();">
    <mx:Script>
    <![CDATA[
    import mx.rpc.http.HTTPService;
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    import mx.rpc.events.FaultEvent;
    import mx.events.ItemClickEvent;
    import mx.collections.ArrayCollection;
    import mx.rpc.events.ResultEvent;
    [Bindable]
    private var arr:ArrayCollection = new ArrayCollection();
    private function callPHP():void
    var hs:HTTPService = new HTTPService();
    hs.url = 'Picture.php';
    hs.addEventListener( ResultEvent.RESULT, resultHandler );
    hs.addEventListener( FaultEvent.FAULT, faultHandler )
    hs.send();
    private function resultHandler( event:ResultEvent ):void
    arr = event.result.root.images.image as ArrayCollection;
    private function faultHandler( event:FaultEvent ):void
    Alert.show( "Fault Response from HTTPService call:\n " );
    ]]>
    </mx:Script>
    <mx:TileList id="tilelist"
    dataProvider="{arr}">
    <mx:itemRenderer>
    <mx:Component>
    <mx:Image source="images/{data}" />
    </mx:Component>
    </mx:itemRenderer>
    </mx:TileList>
    </mx:Application>

  • How can i open pdf files from the web without saving them

    Windows 7
    Firefox 5
    Adobe Reader 9
    when i want to see a web based pdf file i have to save it before opening it instead of it just opening in a pdf window.

    You can't.
    Those PDFs are only accessible on the Mac.
    They can not even be accessed by iOS.

  • Is there how to download music directally from the ipod and save them into the ipod's library?

    I don't want apps like music download pro, download lite...

    For non-iTunes purchased music you need a third-party program like one of those discussed here:
    Copy music from Ipod to new computer...: Apple Support Communities
    For iTunes purchases:
    iTunes Store: Transferring purchases from your iPhone, iPad, or iPod to a computer

  • How to download a text file from the server

    hi everyone,
    can anyone tell me how to download and read a text file from the server and saved in into resource folder.
    with regards
    pallavi

    its really easy
    To read from server, use something like:
    HttpConnection connector = null;
    InputStream inp_stream = null;
    OutputStream out_stream = null;
    void CloseConnection()
         if(inp_stream!=null)inp_stream.close();
         inp_stream=null;
         if(out_stream!=null)out_stream.close();
         out_stream=null;
         connector.close();
         connector = null;
    public void getResponse(String URL,String params)
      try
         if(connector==null)connector = (HttpConnection)Connector.open(URL);//URL of your text file / php script
         connector.setRequestMethod(HttpConnection.POST);
         connector.setRequestProperty("User-Agent","Profile/MIDP-2.0 Configuration/CLDC-1.1");
         connector.setRequestProperty("content-type", "application/x-www-form-urlencoded");
         //connector.setRequestProperty("charset","windows-1251");
         //*** If you need to send ("arg1=value&arg2=value") arguments to script use this:
         out_stream = connector.openOutputStream();
         byte postmsg[] = params.getBytes();
         out_stream.write(postmsg);
         int rc = connector.getResponseCode();//in any case here connection will be opened & closed
         if (rc != HttpConnection.HTTP_OK)
              CloseConnection();
              throw new IOException("HTTP response code: " + rc);
         inp_stream = connector.openInputStream();
         int pack_len = inp_stream.available();
         byte answ[]=new byte[pack_len];
         inp_stream.read(answ);
         CloseConnection();
         ProcAnswer(answ);//process received data
      catch(Exception ex)
         System.err.println("ERROR IN getResponse(): "+ex);
    } And you can read from resource file like
    public void loadFile(String filename)
        DataInputStream dis = new DataInputStream(getClass().getResourceAsStream("/"+filename));
        String str="";
        try
             while (true)
                ch = dis.read();//read character
                if(ch=='\r')continue;//if file made in windows
                if(ch=='\n' || ch==-1)//end of line or end of file
                    if(str.length()==0)continue;//if empty line
                    //do some thing with "str"
                    if(ch==-1)break;//it was last line
                    str="";//next line
                    continue;
                 str+=(char)ch;
           dis.close();
       catch (Exception e)
           System.err.println("ERROR in loadFile() " + e);
    }Welcome! =)
    Edited by: MorskoyZmey on Aug 14, 2008 3:40 AM

  • The dialog box open twice when open file from the server

    I use the following code to download/open file from the server:
    <%
    String filename = "MengxianhuiDocTest.doc";
    String filepath = "D:\\";
    response.setContentType("APPLICATION/OCTET-STREAM");
    response.setHeader("Content-Disposition",
    ??attachment; filename=\"" + filename + "\"");
    java.io.FileInputStream fileInputStream =
    new java.io.FileInputStream(filepath + filename);
    int i;
    while ((i=fileInputStream.read()) != -1) {
    out.write(i);
    fileInputStream.close();
    out.close();
    %>
    If the application runs, the Open or Save dialog box display.When I select open the file,
    the dialog box will display twice.
    Pls help me.
    Thanks.

    thx
    but I tried it and it did't work.
    The dialog box also display twice.

  • Download a file from the web

    Helo,
    I have to download a file from the web and copy it to the file system (ex: download from http://172.26.20.22/test.csv to \\server01\teste.csv).
    I must do this using only pl/sql and java sources, I have to do this calling a procedure from pl/sql and the server doesn't have any component installed.
    I've built a java procedure using java to download the file, but it give-me AccessControlException when trying to download.
    Can anyone tel me what permissions I should have to accomplish this? Is there any other easier way?
    Thanks.

    Thanks a lot! Your post was very helpfull.
    I create a procedure do download the file from the web and record in a network share.
    But I'm still having a problem while writing that each line in my source file generate a duplicate line in my destination one.
    Can you help me with that problem to?
    Thanks
    My procedure is below:
    create or replace procedure SP_DOWNLOAD(astr_url_orig varchar2, astr_cam_dest varchar2, astr_nome_arq_dest varchar2) is
    l_pagina utl_http.html_pieces;
    l_arquivo utl_file.file_type;
    begin
    l_pagina := utl_http.request_pieces(astr_url_orig);
    l_arquivo := utl_file.fopen(astr_cam_dest, astr_nome_arq_dest, 'W');
    for i in 1 .. l_pagina.count
    loop
    utl_file.put_nchar(l_arquivo, l_pagina(i));
    dbms_output.put_line(l_pagina(i));
    end loop;
    utl_file.fclose(l_arquivo);
    end SP_DOWNLOAD;

  • How to download a pdf file from the server from an strut application?

    Hi,
    I wan to download a pdf file from the server side to local system. Please help me how i use the down load option.

    Read up on the Struts download action [1].
    And next time, please post in the relevant forum, one of the web-tier ones [2].
    [1] http://wiki.apache.org/struts/StrutsFileDownload
    [2] http://forum.java.sun.com/category.jspa?categoryID=20
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    ----------------------------------------------------------------

  • When i try download a file from the internet it looks like its downloading then when i go to open this file it opens up in the app text edit and says it cannot open i DOS mode? Can anyne help?

    when i try to download a file from the internet it starts to download but when its finished it opens up in the app "text edit" and it says this file cannot open in DOS mode.
    Can anyone help?

    It sounds like perhaps the file doesn't have an extension that the system recognizes. Is this all files, or just one specific one, and if so, which? What is the name (and extension, if it has one) of the downloaded file? What kind of file do you *expect* it to be? (PDF, or whatever). Renaming a file with the appropriate extension can often fix that kind of problem.
    Matt

  • What are the commands available to read a file from application server and

    What are the commands available to read a file from application server and store the file into an internal table?

    Hi,
    To read a file from an Application Server to an Object there is a command in ABAP called <b>READ DATASET</b>. After that file is transported to that object you have to do a loop and put that data in an Internal Table.
    This statement exports data from the file specified in dset into the data object dobj. For dobj, variables with elementary data types and flat structures can be specified. In Unicode programs, dobj must be character-type if the file was opened as a text file.
    For dset, a character-type data object is expected - that is, an object that contains the platform-specific name of the file. The content is read from the file starting from the current file pointer. After the data transfer, the file pointer is positioned after the section that was read. Using the MAXIMUM LENGTH addition, the number of characters or bytes to be read from the file can be limited. Using ACTUAL LENGTH, the number of characters or bytes actually used can be determined.
    In a Unicode program, the file must be opened with an arbitrary access type; otherwise, an exception that cannot be handled will be triggered.
    If the file has not yet been opened in anon-Unicode program, it will be implicitly opened as a binary file for read access using the statement
    OPEN DATASET dset FOR INPUT IN BINARY MODE.
    . If a non-existing file is accessed, an exception that can be handled can be triggered.
    Influence of Access Type
    Files can be read independently of the access type. Whether data can be read or not depends solely on the position of the file pointer. If the latter is at the end of the file or after the file, no data can be read and sy-subrc will be set to 4.
    Influence of the Storage Type
    The import function will take place irrespective of the storage type in which the file was opened with the statement OPEN DATASET.
    If the file was opened as a text file or as a legacy text file, the data is normally read from the current position of the file pointer to the next end-of-line marking, and the file pointer is positioned after the end-of-line marking. If the data object dobj is too short for the number of read characters, the superfluous characters and bytes are cut off. If it is longer, it will be filled with blanks to the right.
    If the file was opened as a binary file or as a legacy-binary file, as much data is read that fits into the data object dobj. If the data object dobj is longer than the number of exported characters, it is filled with hexadecimal 0 on the right.
    If the specified storage type makes conversion necessary, this is executed before the assignment to the data object dobj. Afterwards, the read data is placed, byte by byte, into the data object.
    System Fields
    sy-subrc Meaning
    0 Data was read without reaching end of file.
    4 Data was read and the end of the file was reached or there was an attempt to read after the end of the file.
    Thanks,
    Samantak.
    <b>Rewards points for useful answers.</b>

Maybe you are looking for