Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

How do I upload files? #6

Closed
chasm opened this issue Jul 10, 2010 · 11 comments
Closed

How do I upload files? #6

chasm opened this issue Jul 10, 2010 · 11 comments

Comments

@chasm
Copy link

chasm commented Jul 10, 2010

I have a form that uploads a file via enctype="multipart/form-data". I know that the site is responding. The input looks like this:

<input type="file" name="photo[upload]" id="photo-upload" size="36" />

On the other end I am looking for the file like this:

param("photo[upload]").get

But I'm not getting anything as far as I can tell. Where is the file? Do I need to add something to web.xml? There is nothing on the site about this that I can find.

Also, I'm looking at using a jQuery plugin for swfupload, which uses Flash to queue files and upload them without reloading the page. I have this working on the browser side, but can't find the files on the server again. Do you have any ideas as to how to handle this? It should be simple, but it is definitely not obvious.

Thanks.

P.S. Where is your mailing list or Google group? You need one.

@inca
Copy link
Owner

inca commented Jul 12, 2010

Hi! I'm quite unsure of what exactly you expect to appear in photo[upload] parameter; as far as I am concerned, there are no built-ins for file uploading in current circumflex version.
This stuff, however, can be very easily implemented with Apache Commons FileUpload.

@chasm
Copy link
Author

chasm commented Jul 12, 2010

I was hoping for an instance of java.io.File.

I'm coming from Lift and Play!, both of which provide this sort of functionality out of the box, so that's what I was looking for. But I get it: it's roll your own in Circumflex. No sweat.

(Actually, while I was waiting for a response, I implemented the app in Play! with Scala/Scalate, but next app. I'm looking forward to using Circumflex soon.)

@inca
Copy link
Owner

inca commented Jul 13, 2010

Okay, we got it in our wish-list for Circumflex 1.2.

@inca
Copy link
Owner

inca commented Jul 20, 2010

Changed my mind.

See, Circumflex is intended to be mini-framework, it does not pretend like it would solve all your problems at once, it just minimizes your effort in dealing with common tasks while still allowing you to use whatever tools you like.

Apache Commons FileUpload is such a tool: it does it's job perfectly, it is flexible, it has many configuration scenarios and can be easily added to any Circumflex application.

Since we make no assumptions on how your application will work (and how you would like commons-fileupload to work for you), we won't add any built-ins for now.

If you require more out-of-box functionality and featurefullness, maybe Circumflex isn't the best choice for you. It's just isn't our way.

Best regards,
Boris Okunskiy

@chasm
Copy link
Author

chasm commented Aug 6, 2010

Sorry, I just now saw this.

I'm totally cool with roll-your-own. I usually do. And I like being able to mix and match. I just didn't have time in this instance to learn a new tool (ACFU) -- the one downside of this approach.

Chas.

@inca
Copy link
Owner

inca commented Aug 26, 2010

Well, I think I've finally came up with a nice way to include FileUpload to Circumflex while still leaving a place for developers to configure it to suit their needs. It will be included in Circumflex 2.0.

@chasm
Copy link
Author

chasm commented Aug 26, 2010

This is great. I do think that file upload is common enough to be considered sort of "part of the package" rather than an add on, but configuration is key. I'll be interested to see what you came up with.

OT: Just converted a Vaadin site to run in Circumflex with no issues. It was surprisingly easy. Vaadin handles the UI (no FreeMarker) and the Circumflex ORM handles the data. I was also able very quickly to create a REST interface to the data as well. Everything is playing nicely together, which is almost unheard of.

@inca
Copy link
Owner

inca commented Aug 27, 2010

Great to hear that! We're looking forward to play well with other libs and frameworks, so your experience means a lot for us. Thanks!

@RyuuGan
Copy link
Collaborator

RyuuGan commented Dec 22, 2010

There is a simple way to upload file using apache common file upload.
import org.apache.commons.fileupload.util.Streams

val m = Map.empty[String, String]
// getting an iterator
val i = request.body.parseFileStreams
while (i.hasNext) {
  val itemStream = i.next
  //getting field name from form
  val name = itemStream.getFieldName
  val stream = itemStream.openStream
  //checking for field is file or normal field
  if (itemStream.isFormField)
    // getting value of normal field
    m += (name -> Streams.asString(stream,"UTF-8").trim)
  else {
    val out = new java.io.FileOutputStream(servletContext.getRealPath("/public/uploads/"
            + itemStream.getName))
    Streams.copy(stream, out, true)
  }

@freewind
Copy link

@RyuuGan, is the code you provided from your scalaqa project? main.scala? I tried it but it throws exception when I submit a question in the demo. Please have a check

@inca
Copy link
Owner

inca commented Feb 12, 2011

I suggest you to start this thread in scalaqa repository.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants