You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by loshmeey <th...@gmail.com> on 2012/04/13 19:47:14 UTC

Uploading Images!

Hello everyone, this is my first post soo i kinda feel i need to introduce
myself :). Im 22, studying IT from Serbia. I had tapestry in one of the
classes on colleague and i really started to like it and i still like it
very much! I mastered all the "basics" (forms, beaneditforms, grids, zones,
working with hibernate to save data to db, and extract it from db etc..) but
now i`ve really hit a wall. 

I want to upload a picture from a .tml page to web server, and on the other
.tml page display that picture...nothing really fancy, but i am really
struggling on doing it! Sooo... pleease help me!! I hope you can  provide
some example code to :)


---
Best Regards
Milos 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-Images-tp5639019p5639019.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Uploading Images!

Posted by loshmeey <th...@gmail.com>.
Thank you very much for the quick response! 

Im gonna try to work my way trough the link you sent me and if i get
stuck... ill come back with more detailed questions!

Thanks again!

@George Christman

nop, not using Jquery for now, but will look into it! Thank you!

--
Best regards
Milos
 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-Images-tp5639019p5639106.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Uploading Images!

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 13 Apr 2012 14:47:14 -0300, loshmeey <th...@gmail.com> wrote:

> Hello everyone,

Hi! Welcome to the mailing list!

> I want to upload a picture from a .tml page to web server,

You can use Tapestry-Upload's Upload component for that.

> and on the other .tml page display that picture...

There's no single approach here, but once you have the image bytes in an  
array, you can create a page to show images. In this page, you'll need to  
have an onActivate() method that returns a StreamResponse wrapping the  
image bytes. Then you'll need to create an URL for this page. You can  
@Inject PageRenderLinkSouce and use one of its methods for that.

http://wiki.apache.org/tapestry/Tapestry5HowToStreamAnExistingBinaryFile  
has some nice examples.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Uploading Images!

Posted by loshmeey <th...@gmail.com>.
soo, i added the code you gave me for example, and i still keep getting file
not found exception. I made folder images in project folder and it still
keeps popping up..so, can anyone help me out with this ? :)

--
Best Regards
Milos

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-Images-tp5639019p5640721.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Uploading Images!

Posted by loshmeey <th...@gmail.com>.
It works! :), thank you very much!

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-Images-tp5639019p5641747.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Uploading Images!

Posted by bhorvat <ho...@gmail.com>.
Here you go a simple code that works

http://tapestry.1045711.n5.nabble.com/file/n5641351/A.java A.java 
http://tapestry.1045711.n5.nabble.com/file/n5641351/A.tml A.tml 

Just make sure that you have a folder named testUpload

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-Images-tp5639019p5641351.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Uploading Images!

Posted by loshmeey <th...@gmail.com>.
right, sorry i forgot to mention the important part! It happens when i click
submit..i still didn`t figure out why it pops up or how ti fix it :/

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-Images-tp5639019p5641284.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Uploading Images!

Posted by bhorvat <ho...@gmail.com>.
I am not sure where do you get an error, when you upload a file or when you
try to display it? 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-Images-tp5639019p5641121.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Uploading Images!

Posted by loshmeey <th...@gmail.com>.
@bhorvat

hehe actually im was at fon, finished first 2 years, and then transferred to
fit! and i am really happy with that decision :D..anyway to the problem im
having. I got the upload to work but.. 

this is the form..pretty simple

<t:form t:id="form">
                <t:upload t:id="file" t:value="file" validate="required" />
                <t:submit t:id="submit" value="submit" />
                </t:form>

and java

public Object onSuccessFromForm(){

        File copied = new File("/testUpload/" + file.getFileName());

        file.write(copied);
        return index;
    }

so my problem is:
if i leave the code like this i get file not found exception, but if i
remove "/testUpload/", it works just fine. So where is the file? And, i am
using glassfish that comes with netbeans to test the app, should i make
/testUpload/ folder maybe on localhost in order to save it there?

--
Best Regards
Milos

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-Images-tp5639019p5640344.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Uploading Images!

Posted by bhorvat <ho...@gmail.com>.
Hej Milos I am also from Serbia (well I have moved now) but I have graduate
from the FON (since you are using the tapestry and if you are on them
faculty then I know your professor - personally)

I will give you some example code so that you can figure things out and if
you need more help feel free to reach out.

So what you need is in your .tml

 <t:form t:id="form">
    <input t:type="upload" t:value="uploadImage" />
                                  
 </t:form>

in your java file you would then have

    @Inject
    private ApplicationGlobals appGlobals;
    @Property
    private UploadedFile uploadImage;


    @OnEvent(value = EventConstants.SUCCESS, component = "form")
    void processForm() {

                if (uploadImage!= null) {
                    String fileName = uploadImage.getFileName());
                    File copied = new
File(appGlobals.getServletContext().getRealPath("/images/") + "/" +
fileName);
                    uploadImage.write(copied);
                } 
    }

So above you check if the file is uploaded and then u get the name, and move
the file to a location where you want it

Hope this gives you a simpel example to try it out

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-Images-tp5639019p5639912.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Uploading Images!

Posted by George Christman <gc...@cardaddy.com>.
Not sure if your using jquery, but have you looked at the tapestry-jquery
ajaxupload component?

http://tapestry5-jquery.com/docs/components/docsajaxupload

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Uploading-Images-tp5639019p5639042.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org