uploading and downloading images

  • makhan
  • Novice
  • Novice
  • makhan
  • Posts: 31

Post 3+ Months Ago

Hi

Can I upload and download images from actions script to server .
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

FileReference constructor
public FileReference()

Quote:
Creates a new FileReference object. When populated, a FileReference object represents a file on the user's local disk.


Availability: ActionScript 1.0; Flash Player 8

Example
The following example creates a new FileReference object and initiates the download of a PDF file.

Code: [ Select ]
import flash.net.FileReference;

var listener:Object = new Object();
listener.onComplete = function(file:FileReference) {
  trace("onComplete : " + file.name);
}

var url:String = "http://www.macromedia.com/platform/whitepapers/platform_overview.pdf";
var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
fileRef.download(url, "FlashPlatform.pdf");
  1. import flash.net.FileReference;
  2. var listener:Object = new Object();
  3. listener.onComplete = function(file:FileReference) {
  4.   trace("onComplete : " + file.name);
  5. }
  6. var url:String = "http://www.macromedia.com/platform/whitepapers/platform_overview.pdf";
  7. var fileRef:FileReference = new FileReference();
  8. fileRef.addListener(listener);
  9. fileRef.download(url, "FlashPlatform.pdf");



See also
browse (FileReference.browse method)
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

upload (FileReference.upload method)
public upload(url:String) : Boolean

Quote:
Starts the upload of a file selected by a user to a remote server. Flash Player can upload files of up to 100 MB. You must call FileReference.browse() or FileReferenceList.browse() before calling this method.


Listeners receive events to indicate the progress, success, or failure of the upload. Although you can use the FileReferenceList object to let users select multiple files to upload, you must upload the files one by one. To do so, iterate through the FileReferenceList.fileList array of FileReference objects.

The file is uploaded to the URL passed in the url parameter. The URL must be a server script configured to accept uploads. Flash Player uploads files using the HTTP POST method. The server script that handles the upload should expect a POST request with the following elements:

A Content-Type element of multipart/form-data
A Content-Disposition element with a name attribute set to "Filedata" and a filename attribute set to the name of the original file
The binary contents of the file
Here is a sample POST request:

Code: [ Select ]
Content-Type: multipart/form-data; boundary=AaB03x
--AaB03x
Content-Disposition: form-data; name="Filedata"; filename="example.jpg"
Content-Type: application/octet-stream
... contents of example.jpg ...
--AaB03x--
  1. Content-Type: multipart/form-data; boundary=AaB03x
  2. --AaB03x
  3. Content-Disposition: form-data; name="Filedata"; filename="example.jpg"
  4. Content-Type: application/octet-stream
  5. ... contents of example.jpg ...
  6. --AaB03x--




You can send data to the server with the upload() call by appending parameters to the URL.

Note: If your server requires user authentication, only SWF files running in a browser--that is, using the browser plug-in or ActiveX control--can provide a dialog box to prompt the user for a user name and password for authentication, and only for downloads. For uploads that use the plug-in or ActiveX control, and for uploads and downloads that use the stand-alone or external player, the file transfer fails.

When using this method, consider the Flash Player security model:

Not allowed if the calling SWF file is in an untrusted local sandbox.
The default is to deny access between sandboxes. A website can enable access to a resource by adding a cross-domain policy file.
For more information, see the following:

Chapter 17, "Understanding Security," in Learning ActionScript 2.0 in Flash
The Flash Player 8 Security white paper at http://www.macromedia.com/go/fp8_security
The Flash Player 8 Security-Related API white paper at http://www.macromedia.com/go/fp8_security_apis

Availability: ActionScript 1.0; Flash Player 8

Parameters
url:String - The URL of the server script configured to handle upload through HTTP POST calls. The URL can be HTTP or, for secure uploads, HTTPS.

You can send data to the server with the upload() call by appending parameters to the URL; for example, http://www.myserver.com/upload.cgi?userID=jdoe

On some browsers, URL strings are limited in length. Lengths greater than 256 characters may fail on some browsers or servers.

Returns
Boolean - A value of false in any of the following situations:

FileReference.browse() has not yet been successfully called on this object, or if FileReferenceList.browse() has not yet been successfully called with this object in its filelist array.
The protocol is not HTTP or HTTPS.
A security violation occurs; that is, if your SWF file attempts to access a file from a server that is outside your SWF files's security sandbox.
The url parameter is of the incorrect type or format.
The call does not have the correct number of parameters.

Events
onCancel - Invoked when the user dismisses the dialog box.

onComplete - Invoked when the file upload operation successfully completes.

onHTTPError - Invoked when an upload fails because of an HTTP error.

onIOError - Invoked in any of the following situations:
The upload fails because of an input/output error while Flash Player is reading, writing, or transmitting the file.
The upload fails because the SWF file tries to upload a file to a server that requires authentication, such as a user name and password. During upload, Flash Player does not provide a means for users to enter passwords.
The upload fails because the url parameter contains an invalid protocol. FileReference.upload() must use HTTP or HTTPS.

onOpen -Invoked when an upload operation starts.

onProgress - Invoked periodically during the file upload operation.

onSecurityError - Invoked when an upload fails because of a security violation.

Example
The following example shows an implementation of the upload() method by first prompting the user to select a file to upload, then handling the onSelect and onCancel listeners, and finally handling the results of the actual file upload.

Code: [ Select ]
import flash.net.FileReference;

var allTypes:Array = new Array();
var imageTypes:Object = new Object();
imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";
allTypes.push(imageTypes);

var listener:Object = new Object();

listener.onSelect = function(file:FileReference):Void {
  trace("onSelect: " + file.name);
  if(!file.upload("http://www.yourdomain.com/yourUploadHandlerScript.cfm")) {
    trace("Upload dialog failed to open.");
  }
}

listener.onCancel = function(file:FileReference):Void {
  trace("onCancel");
}

listener.onOpen = function(file:FileReference):Void {
  trace("onOpen: " + file.name);
}

listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
  trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
}

listener.onComplete = function(file:FileReference):Void {
  trace("onComplete: " + file.name);
}

listener.onHTTPError = function(file:FileReference):Void {
  trace("onHTTPError: " + file.name);
}

listener.onIOError = function(file:FileReference):Void {
  trace("onIOError: " + file.name);
}

listener.onSecurityError = function(file:FileReference, errorString:String):Void {
  trace("onSecurityError: " + file.name + " errorString: " + errorString);
}

var fileRef:FileReference = new FileReference();
fileRef.addListener(listener);
fileRef.browse(allTypes);
  1. import flash.net.FileReference;
  2. var allTypes:Array = new Array();
  3. var imageTypes:Object = new Object();
  4. imageTypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
  5. imageTypes.extension = "*.jpg; *.jpeg; *.gif; *.png";
  6. allTypes.push(imageTypes);
  7. var listener:Object = new Object();
  8. listener.onSelect = function(file:FileReference):Void {
  9.   trace("onSelect: " + file.name);
  10.   if(!file.upload("http://www.yourdomain.com/yourUploadHandlerScript.cfm")) {
  11.     trace("Upload dialog failed to open.");
  12.   }
  13. }
  14. listener.onCancel = function(file:FileReference):Void {
  15.   trace("onCancel");
  16. }
  17. listener.onOpen = function(file:FileReference):Void {
  18.   trace("onOpen: " + file.name);
  19. }
  20. listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
  21.   trace("onProgress with bytesLoaded: " + bytesLoaded + " bytesTotal: " + bytesTotal);
  22. }
  23. listener.onComplete = function(file:FileReference):Void {
  24.   trace("onComplete: " + file.name);
  25. }
  26. listener.onHTTPError = function(file:FileReference):Void {
  27.   trace("onHTTPError: " + file.name);
  28. }
  29. listener.onIOError = function(file:FileReference):Void {
  30.   trace("onIOError: " + file.name);
  31. }
  32. listener.onSecurityError = function(file:FileReference, errorString:String):Void {
  33.   trace("onSecurityError: " + file.name + " errorString: " + errorString);
  34. }
  35. var fileRef:FileReference = new FileReference();
  36. fileRef.addListener(listener);
  37. fileRef.browse(allTypes);




See also
browse (FileReference.browse method), browse (FileReferenceList.browse method), download (FileReference.download method), fileList (FileReferenceList.fileList property)

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 9 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.