Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8134597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:05:31+00:00 2026-06-06T10:05:31+00:00

I am trying to upload a file with playframework. I create a form and

  • 0

I am trying to upload a file with playframework. I create a form and corresponding controller as below :

<form action="@{Admin.testUpload()}" method="POST" enctype="multipart/form-data">
    <input type="text" name="title" />
    <input type="file" name="f1" />
    <input type="file" name="f2" />    
    <input type="submit" value="Send it..." />
</form>


public static void testUpload(File f1, File f2) { 
    System.out.println(f1.getName());
    System.out.println(f2.getName());
}

It is fine now, I can get the file by the instances f1 and f2. However, when I want to pass the file instance to another method, it will occur null pointer exception. Such as :

public static void testUpload(File f1, File f2) {
    test2(f1);
}

public static void test2(File f1) {
    System.out.println(f1.getName());
}

It will cause exception within test2 method. And I found the playframework try to GET the image from a tmp folder. It seems that playframework automatically upload the file to a tmp folder and create a folder with the file name that I uploaded.

Is it the play mechanism?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:05:32+00:00Added an answer on June 6, 2026 at 10:05 am

    When you call a public static method in your controller, Play will perform an HTTP redirect, because it believes you are calling another action.

    So when you are redirecting, the second file object doesn’t exist. You have two options here.

    Firstly, you can make test2 a non-public method.

    Secondly, you can annotate the method with @Util, which tells Play that it is not an action, and therefore will not attempt to redirect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to upload a file with cakePHP. This is the view: echo $form->create(null,
I was trying to upload file(s) using PrototypeJs request method but I failed. The
I am trying to upload a file via a form and then save in
I am using html form below and on my local computer trying to upload
I'm trying to upload PHP file via php using ftp details as mentioned below.
In my code attached below, I'm trying to upload a file via ASP.NET. I
I'm trying to upload a file using PHP. My HTML page with the form
I'm trying to upload file, using XMLHTTPRequest, and sending this headers: Content-Type:multipart/form-data, boundary=xxxxxxxxx --xxxxxxxxx
I'm trying to upload a file and change its name below. I need to
I am trying to upload a file via ftp using FtpWebRequest as below: ftpRequest

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.