Grails: file upload confirmation

My Grails application has a download form, for example:

<g:uploadForm action="save" >
    <input type="file" name="csvfile" />
    <!-- some other inputs ... -->
    <g:submitButton name="upload" value="Save" />
</g:uploadForm>

I do not want to store the contents of the file in a domain object, but I want to transfer it directly to the file using the method transferTo. How can I perform a check in this case (possibly using a command object)?

+3
source share
2 answers

When you upload a file, you can do something like this in your controller:

def myAction = {
    def file = request.get('csvfile')
    file.transferTo(new File('/path/to/local/file'))
}

I do not understand the connection between your question and how the inputs in your form will be displayed on a domain object. If you do not want the contents of a file in your domain, you should not have a domain field defined for them.

, , .

+3

, , @Rob Hruska, . , , .

0

Source: https://habr.com/ru/post/1776752/


All Articles