File Chooser in Flex
I want to make a file chooser that can allow me to choose
(Browse) where's the file that i want to upload. Anyone know how to
create a file chooser with flex builder 2 ? I'm very appreciate for
any answer.
Here is an example that will make a file browser to choose
either an image or mp3 file:
private var upload_ref:FileReference;
private function upload_media():void {
var media_filter:FileFilter;
var filter_array:Array = new Array();
media_filter = new FileFilter("Images (*.jpg, *.jpeg, *.gif,
*.png)", "*.jpg; *.jpeg; *.gif; *.png");
filter_array.push(media_filter);
media_filter = new FileFilter("Audio (*.mp3)", "*.mp3");
filter_array.push(media_filter);
upload_ref = new FileReference();
upload_ref.browse(filter_array);
upload_ref.addEventListener(Event.SELECT, file_selected);
private function file_selected(evt:Event):void {
if (upload_ref.name != null &&
upload_ref.name.search(" ") == -1 &&
upload_ref.name.search("'") == -1) {
var sendVars:URLVariables = new URLVariables();
sendVars.file_path = "/path_on_server_to_upload_to";
var request:URLRequest = new URLRequest();
request.url = "
http://yourserver.com/upload_php_script.php";
request.data = sendVars;
request.method = URLRequestMethod.POST;
upload_ref.addEventListener(Event.COMPLETE, completeUpload);
upload_ref.upload(request);
} else {
Alert.show("File name can only include letters, numbers or
underbars. No spaces.");
Vygo
Similar Messages
-
How can i Upload Files from my Flex 2.0 Application?
How can i do a Upload File funtionality with Flex 2.0? Do i
have to make the component? How is the code in Flex/ Action Script
to make this possible?. I'm new in this Flex world and it seems to
me very interesting to make RIA's Applications; in fact i'm making
a little Employees Application for my company and i'm trying this
technology and of course i need the functionality that i asking
for.
Regards.
Andres.I haven't tried this, but I believe what you could do is
append
requestHeaders to the urlrequest object that you pass into
the file.upload()
method. The requestHeaders is an array of name/value pairs
that would be
included with your post. At least in theory, I believe that
shoudl work.
Good luck.
Phil
"tantalo" <[email protected]> wrote in
message
news:e3q3mt$138$[email protected]..
> Hi. Phil, how i commented in the forum the examples
works ok, with a
> little
> changes to make a file Upload. Now i have another doubt,
i need to make a
> submit of a form with another fields and the file
selected.
>
> I made a HHTP Service for that purpose with the tags
Requests like:
>
> <mx:HTTPService id="empleadoRequest"
> url="
http://andresbarrios:8080/directorio/empleados/insertarEmpleado.jsp"
> useProxy="false" method="POST">
> <mx:request xmlns="">
>
<empresa>{empresa.selectedItem.data}</empresa>
>
<ubicacion>{ubicacion.selectedItem.data}</ubicacion>
>
<departamento>{departamento.selectedItem.data}</departamento>
> <cedula>{cedula.text}</cedula>
> <nombre>{nombre.text}</nombre>
> <apellido>{apellido.text}</apellido>
> <!--Falta Fecha de Nacimiento -->
> <sexo>{sexo.selectedItem.data}</sexo>
>
<estado_civil>{estado_civil.selectedItem.data}</estado_civil>
>
<telefono_celular>{telefono_celular.text}</telefono_celular>
> <extension>{extension.text}</extension>
>
<correo_electronico>{correo_electronico.text}</correo_electronico>
> </mx:request>
> </mx:HTTPService>
> I have the global variable called "file" that contains
the file selected.
> I
> want to send this file variable in the HHTPservice call
EmpleadoRequest,
> can i
> do that with a Request tag like another field? or the
only way is trougth:
> file.upload(upload.cfm) ?;
>
> I want only make a one call to the server to submit the
fields of the form
> and
> to upload the file at th e same time can you help me How
can i do that?
>
> Thanks.
>
> Regards.
>
> Andres.
>
>
> -
How to find if the user has selected one or many files using a file chooser
I have a file chooser but want it to return either a file or file array depending on whether more than one file is selected but there doesn't seem to be any way to find out if that is the case or not. I want it to look something like:
if(fileChooser.getSelectedFile().isDirectory()==true)
selectedFile=fileChooser.getCurrentDirectory();
else if(fileChooser.multipleFilesSelected())
fileChooser.getSelectedFiles();//we have more than one file selected
else
fileChooser.getSelectedFile(); //if we have one file selected
}am I going about dealing with this in the right way?OK, I scoured the API again and found I could avoid the problem altogether by using
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFileChooser.html#isMultiSelectionEnabled()
and
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFileChooser.html#setFileSelectionMode(int) -
Need help adding a default file name in a file chooser of save dialog type
I need to create a file chooser with save dialog type, how can I add a highlighted default file name into the File Name textfield? As in Microsoft Word, when you want to save a document, a default file name Doc1.doc will appear in the File name text field of the file chooser even when you change to other directories.
For JRE 1.4.0 you can use this fix:
public class FileChooserFix implements PropertyChangeListener {
private String fileName;
* @see PropertyChangeListener
public void propertyChange(PropertyChangeEvent ev) {
JFileChooser chooser = (JFileChooser)ev.getSource();
if (JFileChooser.FILES_ONLY == chooser.getFileSelectionMode()) {
if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(ev.getPropertyName())) {
File selectedFile = (File)ev.getNewValue();
if (selectedFile != null) {
// remember fileName of selected file
fileName = selectedFile.getName();
if (fileName != null &&
JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(ev.getPropertyName())) {
// reset selected file
File directory = (File)ev.getNewValue();
chooser.setSelectedFile(new File(directory, fileName));
* Convenience method to create a fixed file chooser.
* @return fixed file chooser
public static JFileChooser create() {
JFileChooser chooser = new JFileChooser();
chooser.addPropertyChangeListener(new FileChooserFix());
return chooser; -
File chooser to buffered image
Hi all,
Sorry about the total newbie question; I'm trying to figure out how to convert a jpg into a buffered image, while using the file chooser to select it. I'd like to do all this in a scrollpane. Does anyone have some sample code for this, at least so I can play around? I have ideas, but I'm getting tons of errors while trying things like:
public class ImProc extends JComponent{
private BufferedImage source, destination;
private JComboBox options;
public ImProc( BufferedImage image){
source = destination = image;
setBackground(Color.white);
setLayout( new BorderLayout());
JPanel controls = new JPanel();
options = new JComboBox(
new String[] {"[source]", "brighten", "darken", "rotate", "scale" }
options.addItemListener(new ItemListener(){
public void itemStateChanged( ItemEvent ie){
String option = (String)options.getSelectedItem();
BufferedImageOp op = null;
if(option.equals("[source]"))
destination = source;
else if(option.equals("brighten"))
op = new RescaleOp(1.5f, 0, null);
else if(option.equals("darken"))
op = new RescaleOp(0.5f, 0, null);
else if (option.equals("rotate"))
op = new AffineTransformOp(
AffineTransform.getRotateInstance(Math.PI / 6), null);
else if (option.equals("scale"))
op = new AffineTransformOp(
AffineTransform.getScaleInstance(.5, .5), null);
if(op != null) destination = op.filter(source, null);
repaint();
controls.add(options);
add(controls, BorderLayout.SOUTH);
public void paintComponent(Graphics g){
int imageWidth = destination.getWidth();
int imageHeight = destination.getHeight();
int width = getSize().width;
int height = getSize().height;
g.drawImage(destination,
(width - imageWidth) / 2, (height - imageHeight) / 2, null);
public static void main(String[] args){
JFileChooser chooser = new JFileChooser();
String filename = chooser.getName();
ImageIcon icon = new ImageIcon(filename);
Image i = icon.getImage();
int w = i.getWidth(null), h = i.getHeight(null);
BufferedImage buffImage = new BufferedImage(w, h,
BufferedImage.TYPE_INT_RGB);
Graphics2D imageGraphics = buffImage.createGraphics();
imageGraphics.drawImage(i, 0, 0, null);
JFrame frame = new JFrame("Image");
frame.getContentPane().add(new ImProc(buffImage));
frame.setSize(buffImage.getWidth(), buffImage.getHeight());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
So, I'm stuck. Any help from anyone is appreciated.
Thanks,
JoeNow, with:
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
import java.io.*;
import javax.imageio.*;
public class ImProc extends JComponent{
private BufferedImage source, destination;
private JComboBox options;
public ImProc( BufferedImage image){
source = destination = image;
setBackground(Color.white);
setLayout( new BorderLayout());
JPanel controls = new JPanel();
options = new JComboBox(
new String[] {"[source]", "brighten", "darken", "rotate", "scale" }
options.addItemListener(new ItemListener(){
public void itemStateChanged( ItemEvent ie){
String option = (String)options.getSelectedItem();
BufferedImageOp op = null;
if(option.equals("[source]"))
destination = source;
else if(option.equals("brighten"))
op = new RescaleOp(1.5f, 0, null);
else if(option.equals("darken"))
op = new RescaleOp(0.5f, 0, null);
else if (option.equals("rotate"))
op = new AffineTransformOp(
AffineTransform.getRotateInstance(Math.PI / 6), null);
else if (option.equals("scale"))
op = new AffineTransformOp(
AffineTransform.getScaleInstance(.5, .5), null);
if(op != null) destination = op.filter(source, null);
repaint();
controls.add(options);
add(controls, BorderLayout.SOUTH);
public void paintComponent(Graphics g){
int imageWidth = destination.getWidth();
int imageHeight = destination.getHeight();
int width = getSize().width;
int height = getSize().height;
g.drawImage(destination,
(width - imageWidth) / 2, (height - imageHeight) / 2, null);
public static void main(String[] args){
JFrame frame = new JFrame("Image");
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JFileChooser chooser = new JFileChooser();
//String filename = chooser.getName();
File f = chooser.getSelectedFile();
//String filename = f.getName();
//ImageIcon icon = new ImageIcon(filename);
//Image i = ImageIO.read(f);
//int w = i.getWidth(null), h = i.getHeight(null);
//BufferedImage buffImage = null;
try{
BufferedImage buffImage = ImageIO.read(f);
catch (IOException e){
System.out.println("Error: " + e.getMessage());
frame.getContentPane().add(new ImProc(buffImage));
Graphics2D imageGraphics = buffImage.createGraphics();
imageGraphics.drawImage(buffImage, 0, 0, null);
With this, it doesn't seem to find my variable buffImage. However, it complains if I don't use the try{} catch{}. Am I not declaring something properly? -
Default settings for File Chooser dialog
I reach the file chooser dialog by selecting File-Open File.
Under the toolbar-options menu in the Open File Dialog, I can select to have a bookmark icon appear on the toolbar.
How do I set a default to have the Bookmark icon always appear?
Firefox 11 on openSuSE 12.1I don't think so, if I hide the Menu bar I don't see a Bookmarks Menu.
In this picture http://dl.dropbox.com/u/50261731/Open_File%20Menu%20.png an arrow points to an Options menu button. Select that Button and a list of options opens, one of which is "Show Bookmarks". I would like the Show Bookmarks option to be "ON" by default.
Be aware that I am running SuSE 12.1 and I believe this Menu is provided by KDE integration "kmozillahelper", so my menu may be different from the default Firefox menu. -
Hello,
I need to design a custom file chooser. Infact, I cannot call it a file
chooser, because this is not accessing local system files. I am uploading
some files into a directory using ASP and I keep that file name in the database.
I can even upload directores and directores with files too into the database.
I need to display those files and folders in the "what is called as file chooser".
The List should work as it works in file chooser. i.e when I click on a folder,
it should show the files inside it. When I click on the file, the file should
be selected. Infact there is nothing in the file. Its all virtual only. Its only
the name that is selected.
I should be given an option to select "directories only" also.
The "file chooser" should not have show files of type, just the file name
text field only. The combobox should display "user added" string message. And
this is only one item in the combobox. I should be able to create folders, show
lists,etc... as it appears in the file chooser. (buttons beside the combobox)
Any ideas would be greatly appreciated.
Thanksok, this is just an example....you'll probably need a different constructor and additional methods....
public class VirtualFile{
private String file ;
private VirtualFile[] children;
private VirtualFile parent;
public VirtualFile(String file,VirtualFile parent,VirtualFiles[]children){
this.file = file;
this.parent = parent;
this.children = children;
public boolean isRoot(){
return parent == null;
public boolean isDirectory(){
return children = null || children.length==0;
public VirtualFile[] getChildren){
return children;
} -
File Chooser in a Panel - please help
Hello!
I am implementing a FTP program as part of an assignment. Can you please tell me how I can get a File Chooser like interface to the files on the remote computer? Can the existing JFileChooser be modified to support this and also can it be embedded in a panel rather than opening in a separate dialog box? Is there any way to get drag and drop support in it?
Please do help
Thanks
DilipHi!
Actually, you can use JFileChooser for remote filesystems. I've implemented it once using JDK 1.3.1 (accessing a remote Linux machine over RMI in an applet):
(1) Create your own subclass of java.io.File, hooking all methods that actually access the filesystem (isDirectory, getSize, ...) to your ftp-connection. (That's the main work, about 50 methods to overwrite, but you can skip many, e.g. createTemporaryFile).
(2) Make your own subclass of FileSystemView to deliver objects of your File-class instead of Sun's.
(3) Initialize JFileChooser with this FileSystemView.
You may also take a look at
http://www.crocodile.org/listok/2/WhatDoesFileSystemViewView.shtml . -
Hi.
I have a JFrame (main frame), that opens another JFrame (popup frame) when u click a button, and in this frame I have a file chooser. The problem is, when i open the file chooser, the popup frame closes (shuts down) while the main frame stais put. How can i prevent the popup frame from closing when clicking the file chooser button?
here's the code for the file chooser:
FileChooser fc = new FileChooser();
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION)
File file = fc.getSelectedFile();
String fileName = file.getName();
JDialog chooseFileFrame = new JDialog();
Container content2 = chooseFileFrame.getContentPane();
content2.show();Nope. both main frame and popup frame are JFrames. Here's the rest of the code:
I have a JFrame, fullcreen, contains a button Button_popup, that calls a new JFrame:
//call file chooser button
JButton chooseFileButton = new JButton("choose file");
//popup frame (that closes when i opens the file chooser
JFrame popUp= new JFrame("Heading");
popUp.setUndecorated(true);
popUp.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
popUp.setBounds(0,0,600,500);
Container content = popUp.getContentPane();
content.setBackground(Color.white);
content.add(chooseFileButton);
adds the file chooser button to my action listener, if hit:
private void chooseFile()
if (returnVal == JFileChooser.APPROVE_OPTION)
File file = fc.getSelectedFile();
String file= file.getName();
JDialog fileChooserDialog= new JDialog();
Container content = fileChooserDialog.getContentPane();
content.show();
} -
Access file object from flex web app
Hi all,
I want to access file object from flex web app. What should i do?
I have to take array from my XML. In XML there will be only dir path. So for taking file name from dir i have to access it and have to perform for loop on that dir.
What should I do?
Any Ideas?
Thanks,
-CKHi Michael
My question is that I dont want to give name of images in XML file.
In XML file there will be only path of image directory. So I need to find all image name from that image directory.
Thats why I want to access file object.
Any ideas? -
How to insert a swf file in to flex..
hi all
i'm trying to insert a swf file in my flex. I'm trying to insert a help manual e-book to my flex application,
i dont have any idea in flex... i have some 1 month experiance in flex...
so plzzz help me...Are you just looking to load an external swf into your flex application? Are there any requirements where the external swf has to be stored like on a different domain or can it be packaged with your Flex app?
-
File Chooser is displaying names of the Files and Directories as boxes
Hi All,
Actually i am working on an application in which i have the requirement to internationalize the File Chooser in All Operating Systems. The application is working properly for all languages on MAC OS, but not working properly for the language Telugu on both the Ubuntu and Windows OS. The main problem is, when i try to open the File Chooser after setting the language to TELUGU all the labels and buttons in the File Chooser are properly internationalized but names of Files and directories in the File Chooser are displaying as boxes.
So please provide your suggestions to me.
Thanks in Advance
Uday.I hope this can help you:
package it.test
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
* @author Alessandro
public class Test extends JDialog {
private JFileChooser fc = null;
private Frame bfcParent = null;
public Test(Frame parent, boolean modal) {
super(parent, modal);
this.bfcParent = parent;
if (fc == null) {
fc = new JFileChooser();
fc.setAcceptAllFileFilterUsed(false);
fc.setLocale(Locale.ITALIAN);//i think you should use english
//these are in telugu
UIManager.put("FileChooser.openDialogTitleText", "Open Dialog");
UIManager.put("FileChooser.saveDialogTitleText", "Save Dialog");
UIManager.put("FileChooser.lookInLabelText", "LookIn");
UIManager.put("FileChooser.saveInLabelText", "SaveIn");
UIManager.put("FileChooser.upFolderToolTipText", "UpFolder");
UIManager.put("FileChooser.homeFolderToolTipText", "HomeFolder");
UIManager.put("FileChooser.newFolderToolTipText", "New FOlder");
UIManager.put("FileChooser.listViewButtonToolTipText", "View");
UIManager.put("FileChooser.detailsViewButtonToolTipText", "Details");
UIManager.put("FileChooser.fileNameHeaderText", "Name");
UIManager.put("FileChooser.fileSizeHeaderText", "Size");
UIManager.put("FileChooser.fileTypeHeaderText", "Type");
UIManager.put("FileChooser.fileDateHeaderText", "Date");
UIManager.put("FileChooser.fileAttrHeaderText", "Attr");
UIManager.put("FileChooser.fileNameLabelText", "Label");
UIManager.put("FileChooser.filesOfTypeLabelText", "filesOfType");
UIManager.put("FileChooser.openButtonText", "Open");
UIManager.put("FileChooser.openButtonToolTipText", "Open");
UIManager.put("FileChooser.saveButtonText", "Save");
UIManager.put("FileChooser.saveButtonToolTipText", "Save");
UIManager.put("FileChooser.directoryOpenButtonText", "Open Directory");
UIManager.put("FileChooser.directoryOpenButtonToolTipText", "Open Directory");
UIManager.put("FileChooser.cancelButtonText", "Cancel");
UIManager.put("FileChooser.cancelButtonToolTipText", "Cancel");
UIManager.put("FileChooser.newFolderErrorText", "newFolder");
UIManager.put("FileChooser.acceptAllFileFilterText", "Accept");
fc.updateUI();
public int openFileChooser() {
fc.setDialogTitle("Open File");
fc.resetChoosableFileFilters();
int returnVal = 0;
fc.setDialogType(JFileChooser.OPEN_DIALOG);
returnVal = fc.showDialog(this.bfcParent, "Apri File");
//Process the results.
if (returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("Hai scelto di aprire un file");
} else {
System.out.println("hai annullato l'apertura");
return returnVal;
private static void createAndShowGUI() {
JFrame frame = new JFrame("FileChooser");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel jp = new JPanel(new BorderLayout());
JButton openButton = new JButton("Open File");
final Test test = new Test(frame, true);
openButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
test.openFileChooser();
openButton.setEnabled(true);
jp.add(openButton, BorderLayout.AFTER_LAST_LINE);
//Add content to the window.
frame.add(jp);
//Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//Turn off metal's use of bold fonts
createAndShowGUI();
}bye ale -
While downloading apps from iTunes Store following error is repeatedly coming "The files seems to be corrupted. To redownload the file, choose "Check for Available Downloads" from the Store menu."? Please suggest any solution.
Contact itunes support.
-
Hi all
I open the file chooser in save mode.when a new folder is created using the 'New Folder" icon, to edit the name of the folder I have to click on it to edit it.But I want When I will create a New Folder it must be in edit mode.Can anyone help me to solve the problem.
thanksOn my system thats exactly what happens, maybe this is new for 1.5 (can't rememeber if it used to or not) what version are you using?
Alex -
Im using file chooser to select the location and a file to save some text to, the question i need help with is can you allocation you own customer file extension to a new file ie text.kelvinstext
thanks,
kelvinSorry if taht came across wrong it was suppose to be
a little heart remark,No need to apologize although the thank you I'm sure is appreciated all round.
For the most part most veterans answering questions here have pretty thick skins. We do however sometimes get frustrated when answering the same questions over and over. It's not your (ie newb / OP / not just u specifically) fault; we're just trying to train you all so that hopefully you'll be able to find your answers independently in the future.
Maybe you are looking for
-
RFC lookup in Integration Scenario
Hi, I have a scenario where I need to do RFC lookup first and based on the values ( typically the lookup will give file path and file name), I need to send these values as variable substitution to file adapter to read the file. The above is in loop u
-
Ok this question may be a little complicated so I'll start by explaining what I'm trying to achive. I have 3 OVM 2.2.1 servers in 1 Server pool running OCFS2 on an EMC SAN. I also ave an Oracle Enterprise Linux server which connects to the same ocfs2
-
Help plz ipod id not recnized by computer
it norenizing my ipod i need help i used disk mode it dont work nither dose the 5rs my ipod was synic wit another compur and i need help plz
-
Logical standby on 10.1.0.3
Hi, what is the procedure to set up a logical standby database on 10.1.0.3. Thank in advance, Regards, Mannu
-
Workflow - syndication problem
Dear All We have the workflow with syndication step. All has been working fine, but sudenly today syndication is not working. There is only an information in log: "The system cannot locate the resource specified. Error processing resource " What does