select image, show it, then send it to localhost via php

57 views
Skip to first unread message

Mohamed Melek CHTOUROU

unread,
May 10, 2021, 10:27:34 PM5/10/21
to CodenameOne Discussions
Hi everyone, i'm a begginer and i'm trying to openGallery to select an image, then show it in a ImageViewer, then send it through php to my localhost
So far i opened the gallery and selected the image ... but i have no clue on how to show it and send it, any kind help ?

Mohamed Melek CHTOUROU

unread,
May 10, 2021, 10:29:10 PM5/10/21
to CodenameOne Discussions

 browse.addActionListener((evt) -> {
            Display.getInstance().openGallery(new ActionListener() {
                public void actionPerformed(ActionEvent ev) {
                    if (ev != null && ev.getSource() != null) {
                        String chemin = (String) ev.getSource();
                       
                        int index = chemin.lastIndexOf('/');
                        if (index > 0) {
                            filename = chemin.substring(index + 1);
                            System.out.println(filename);
                            try {
                                Image img = Image.createImage(chemin);
                                ImageViewer a = new ImageViewer(img);
                                content.add(a);
                                
                            } catch (IOException ex) {
                            }
                        }
                    }
                }
            }, Display.GALLERY_IMAGE);
        });

here's the code i'm having 

Shai Almog

unread,
May 10, 2021, 11:09:07 PM5/10/21
to CodenameOne Discussions
You can use the standard multipart upload. It works like a standard HTML form with file field so should be pretty easy to process on the server side:
https://www.codenameone.com/javadoc/com/codename1/io/MultipartRequest.html

Mohamed Melek CHTOUROU

unread,
May 11, 2021, 5:08:43 AM5/11/21
to codenameone...@googlegroups.com
Thank you so much for your fast reply sir !
I will see right away this and hopefully get to a good output !
And what about the imageview ? What is missing in my code ? I want it to show the image one i clicked on the "parcourir" button, but nothing is showed 

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/3d8cbf45-2db6-4488-b33f-2898fcc026e2n%40googlegroups.com.

Hannah R

unread,
May 11, 2021, 9:58:21 AM5/11/21
to CodenameOne Discussions
Maybe try to reformat your code to the following style, maybe it will help:

browse.addActionListener((evt) -> {
     ActionListener callback = e -> {
            if (e != null && e.getSource() != null) {
String filePath = (String) e.getSource();
                //System.out.println("FILEPATH TO THE IMAGE " +filePath);
               try {
Image img = Image.createImage(filePath);
ImageViewer iv = new ImageViewer(img);

add(iv);
revalidate();

} catch (IOException ex) {

}
}
    };
Display.getInstance().openGallery(callback, Display.GALLERY_IMAGE);
});

Mohamed Melek CHTOUROU

unread,
May 11, 2021, 2:55:46 PM5/11/21
to codenameone...@googlegroups.com
hello there and thank you
i got this error message when trying your code
java.lang.IllegalArgumentException - Cannot add component to BorderLayout Container without constraint parameter

Mohamed Melek CHTOUROU

unread,
May 11, 2021, 2:59:23 PM5/11/21
to codenameone...@googlegroups.com
oups nevermind, all i had to do is to add  add(BorderLayout.SOUTH,iv);
Reply all
Reply to author
Forward
0 new messages