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 7578187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:22:22+00:00 2026-05-30T17:22:22+00:00

So I am trying to do, what I thought, was a simple file read

  • 0

So I am trying to do, what I thought, was a simple file read and import. So the way my code works now is that I have a file stored in a folder on the server, select it, and import it. I select the file through a multipartfile:

    <g:form method="post"  enctype="multipart/form-data" controller="fileManager">
        <label>Company Name:</label><input id="cname" type="text" name="cname" /><br />
        <label>Select a CSV file to upload:</label> <input type="file" id="newFile" name="newFile" /> 
        <g:actionSubmit action="importContactsFromFile" value="Import" />
    </g:form>

So what I want to do is to:

  • Have user select a file
  • Download the file to a directory on the server (input/output stream?)
  • Read the file contents (CSVReader) and import into DB (this works)
  • Possibly clean up file after

So I have a massive headache with that second step. I pull the file into a def variable:

def newFile = request.getFile('newFile')

How do I bridge this gap? Slamming my head over this! Thanks!

  • 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-05-30T17:22:23+00:00Added an answer on May 30, 2026 at 5:22 pm

    Do you need to save the file as an intermediate step before parsing it? Most CSV parsers (OpenCSV for example) will read from a Reader or InputStream directly. So you can do something like:

    def newFile = request.getFile('newFile')
    def csv = new CSVReader(newFile.inputStream.newReader())
    ...
    

    If you want to save the file, you can use the transferTo method:

    def newFile = request.getFile('newFile')
    newFile.transferTo(new File('newFile.csv'))
    def csv = new CSVReader(new File('newFile.csv').newReader())
    

    In that case, you’ll have to ensure two requests don’t overwrite each other by ensuring unique a file name.

    You can find more information in the grails manual: http://grails.org/doc/latest/guide/theWebLayer.html#6.1.9%20Uploading%20Files

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

Sidebar

Related Questions

I have some simple text file. I am trying to read that file contents
Say that I have the Python code: someString = file(filename.jpg).read() How can I replicate
I am trying to do something I thought would be simple. I have a
I'm trying to do something that I thought ought to be reasonably simple but
Just trying to do a (I thought) simple callout to read a number from
I am trying to read database scripts in a Jar file so that I
I'm trying to simulate some code that I have working with SQL but using
I'm trying to read into R a csv file that contains information on political
actually I thought I was trying something really simple. ControllerClassNameHandlerMapping sounded great to produce
I'm trying to do something which I thought would be fairly simple. Get IIS

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.