Client side images in Flex - apache-flex

I am developing an application that includes JPG and TIFF image size validation.
The backend is done is done in PHP. I am wondering if there is anyway to
validate the minimum width and height of those images in Flex or if they have to
be uploaded to PHP and validated there.
Thank you in advance for any assistance,
Orville

In Flash Player 10 the application can gain direct access to data on the client's machine. The new API methods are FileReference.load() and save(); you'll want to use load() to access the file off the user's machine and examine its properties. Details here:
http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html#load()
After the FileReference dispatches its complete event, the "data" property will be populated with a ByteArray of the file's contents. If you can find or write suitable libraries for JPEG and TIFF files then you should be able to examine the dimensions.
For Flash Player 9 and earlier, FileReference is limited to upload() and download().

Assuming you're talking about client-side validation, you could always load the image to an object in flex and test the width and height of the loaded image object manually.
However, this should be done in addition to server-side checking if this limit is important, as client-side checks can be circumvented by crafty users.

Related

Is there a way to get Image data when Image is not from the same domain?

I heard there is a setting that I can change to allow images from remote domains to work? Or is it that I am supposed to call Security.allowDomain() method at some point? I would rather just change a setting on the Image component instance if available?
From the documentation:
SecurityError The target object and all of its child
objects do not come from the same domain as the caller, or are not in
a content that is accessible to the caller by having called the
Security.allowDomain() method.
More info:
IIRC there was a property on the mx:Image component? I'm using Spark Image component in my project but knowing what that is may help me figure out a solution for the Spark Image.

pass FileReference between two flash movies

I have an html page with a flash object that provides video chat using stratus.
I want to enable file sharing from a different UI on the same html page.
I want to use the same stratus connection to send the file.
Is it possible to create a small flash object that will present a browse button and let the user choose a file and then pass the FileReference or file details to the stratus object to send it?
Thanks
If the two SWFs are on the same page, you should be able to the LocalConnection API to allow two way communication between the two movies.
I have not directly tried this approach for passing a FileReference object, but it is worth noting that there is a filesize restriction of 40K when using LocalConnection.send() - you may be able to get around this by serialising your FileReference object first and sending it over in chunks.

Assuming ASP.NET and form upload, any way to ensure file is an image?

Is there any way to tell if the file is an image either through MIME type or some other way of inspection? The images are going into a gallery and I'll be resizing them as necessary and want to ensure, to the best I can, that the file I'm about to process with GDI is, in fact, an image.
Try to load the file into a Bitmap object. If if you get an exception then it isn't an image.
Check out this question/answer on stackoverflow and this one. I belive this is a duplicate question.
Also, look into reading a file's magic number especially if you are just trying to determine if the file is one of a few acceptable types. Magic number Wikipedia
Yes, you can check the fileUploadCtrl.PostedFile.ContentType property and compare that string to an expected list of image MIME types i.e. image/gif. You can also perform additional validation by loading the uploaded image bytes into a System.Drawing.Image object. If it loads you know you have a good image, if it fails to load then perhaps the image is a forgery or an unknown format.

Performing function on node click in tree and then showing results in text box

I have a tree object which is bound to an XML list. The XML list contains a name for the type of code I have written (e.g. IM client) and also a path to the file where I have some code.
When the user selects a node's child in the tree, I want to load the file from the path of the selected node's child and then show the text in a text box.
How can I go about this? Is it possible without a server side language?
Thanks
All the relevant files are sitting on the server (e.g. code samples). I don't need to get anything from the user's PC.
You need to use HTTPService or a similar object to make a call to your server and when loading is complete you can display it.
Flash is really restrictive on fetching files from the user's computer. To get around this, I have an application running on the user's computer that acts as the middle man between my Flex app and the files on the computer.
Edit: If you want to load files that you have on the server, then you would need something on the server side to relay that information back to your flex app. Flash runs in the browser, on the client-side, therefore it really doesn't have knowledge of where it actually lives.
Though, since you have those file paths, could you just put a relative path from the root of your server on the end of your domain name to find the files?
http://domain.com/path/file.jpg
It's hard to give a solution without knowing the XML data structure. However, a good place to start is to listen to the tree's change event. You can then get the selectedItem from the tree and that should be the XML node which was clicked.
You say you should have a path to the file at this point, so it's just a matter of loading the file with a request using the URLLoader class.

flex - check image dimensions before upload using filereference

In my Flex application, I use a FileReferenceList that the user can populate with multiple files using fileList.browse() before upload.
I check each file's size and use fileList[i].upload() to upload to my server, this works fine.
I have a suspicion that this is not possible, but before upload I would like to convert each FileReference into an Image in order to check it lies within certain dimension tolerances.
I realise I can do this server side, but ideally I would like the check to appear on both client and server. Can anyone offer any help?
Thanks!
Take a look at this post at the Yahoo! Flash Blog. Flash 10 lets you work with images locally. They give a nice example with code of how you can process FileReference objects, specifically image files.

Resources