|
Hi all,
I am doing a project for file uploading. I just created no domain or controller intially. I just created few gsp files all are html pages saved with .gsp extension. These pages are login and signup forms. It all run's well.
In my signup form, i have a field for fileupload. For which i have written the form code inside the signup.gsp <label for="file">Attach File<span class="req">*</span></label>
<g:uploadForm action="upload"> <input type="file" name="myFile" />
<input type="submit" /> </g:uploadForm> </p> So, this uploadform called "upload" action, when i run the project, so i need to define upload in the controller. Since i have not created any controller yet, i just created a controller can mainController.groovy and defined this
class MainController { def index = { } def upload = { def f = request.getFile('myFile') if (f.empty) { flash.message = 'file cannot be empty'
render(view: 'uploadForm') return } f.transferTo(new File('C:/testing/image')) flash.message = 'Upload success'
response.sendError(200, 'Done') } When i run the project, I am able to upload file but it does not save in the specified local system i.e "C:/testing/image"
What is wrong i m dng!! -- Cheers, Saravana |
|
This post has NOT been accepted by the mailing list yet.
This post was updated on .
You should mention the format type to transfer.If you are uploading image then you can use gif,jpeg,png..
Ex: f.transferTo(new File('C:/testing/image')) Instead try f.transferTo(new File('C:/testing/image.png')) Also make sure image should not be folder Thanks, Bhuvana |
|
In reply to this post by saravanataee
Like I said, read documentation
.http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/web/multipart/MultipartFile.html#transferTo%28java.io.File%29
It should be a file like: new File("C:/testing/image/{f.orginialFilename}") and not a directory. On Thu, Jul 5, 2012 at 4:15 PM, Saravanan S <[hidden email]> wrote: Hi all, Thanks and regards, Ravi Teja |
| Powered by Nabble | Edit this page |
