Posting files from a Desktop Application

Ok, I have an insanely crazy request, but it's a request
nonetheless. I have a client that wants to me to create an
application for viewing photos online. Sounds easy enough, right?

Well, here's the kicker, I developed the application using the
Paperclip plugin and provided him with a snazzy interface for
uploading/managing images from the site itself. He's bound and
determined to have a Desktop application that uploads images to the
server without needing the web interface.

I've been over this a million times with him, but he "feels more
comfortable" with a Desktop application for managing the uploads...

He is a very kind (albeit, uninformed and eccentric) client so I'd
like to make him happy. That said, how in the world should I go about
integrating a Desktop application for upload and have the rails app
"discover" the images? The current functionality is too tied to the
Paperclip plugin to simply drop it. That said, I the way I see it, I
have two options:

1) Provide an upload URL of some sort for the application to access
over HTTP and upload files directly to the app.

2) Provide a folder for FTP on the server that rails then scans and
enters into the system.

My issue is, with the second mechanism (which I'm sure he'll request
explicitly), I'm having severe trouble wrapping my head around getting
the information from a "file" entered into the application while
putting Paperclip "in-the-know" so to speak.

Any input would be much appreciated.

Regards.

P.S. my apologies for the rambling nature of this post

Uh, you realize a browser is a "Desktop Application", yes? :slight_smile:

So you create a simple desktop app that POSTs the images to your
Rails app, to the identical URL, just like a browser does.

Heck, you could probably put a graphical wrapper around curl and
be out the door by lunch :slight_smile:

FWIW,

Just write a simple web browser program that does not look like a web
browser and configure it to always go to his site on startup. Don't
tell him that under the skin its reallly just a web browser. Instead
call it something creative like "Picture Uploader".

I'm sorry all. I should have been more clear. Basically, he has
other applications that pull from some "repositories" on his home
machine. He wants a "Desktop Application" to pull from his computer
at regular intervals and push the photos to the server.

As far as the existing Rails app, I'm using the Paperclip plugin to
manage attachments and whatnot. How would I go about integrating the
"Desktop Application" solution with his existing "automatically-grab-
them-from-my-local-computer" requirements?

Regards.

I'm sorry all. I should have been more clear. Basically, he has
other applications that pull from some "repositories" on his home
machine. He wants a "Desktop Application" to pull from his computer
at regular intervals and push the photos to the server.

OK, if it's automatic/periodic, all you need is cron + curl; nicely done. :slight_smile:

As far as the existing Rails app, I'm using the Paperclip plugin to
manage attachments and whatnot. How would I go about integrating the
"Desktop Application" solution with his existing "automatically-grab-
them-from-my-local-computer" requirements?

I don't understand the question. Whatever plugins you're using, the
file upload is a multipart POST. You can do that without a browser.
Unless Paperclip includes some JavaScript magic it relies on, there
shouldn't be anything you need to do differently on the client side.

OK, if it's automatic/periodic, all you need is cron + curl; nicely done. :slight_smile:

Excellent!

I don't understand the question. Whatever plugins you're using, the
file upload is a multipart POST. You can do that without a browser.
Unless Paperclip includes some JavaScript magic it relies on, there
shouldn't be anything you need to do differently on the client side.

Awesome! I don't believe it does. Is this simply a matter of POSTing
to the "/photos" route? I suppose the only requirement now would be
to get around Rails' "forgery_protection" no? If you could provide an
example, that would be great, otherwise, I'm headed to google "curl +
multipart post"

Thanks so much!

mmm. I've done this with Java servlets, and it just involved using
an appropriate jsessionid cookie with curl, but I haven't yet had to
implement with Rails. So conceptually the same, shouldn't be too
tough to suss out the difference(s) :slight_smile:

Good luck!

Fair enough. So, assuming that I *can* disable all validation of any
sort, the POST is straightforward? I'm constructing something as we
speak, btw.

forgery protection disable should be simple

skip_before_filter :verify_authenticity_token, :only=>:upload_action_name

Nice. Well, I've got dummy POSTs being created, but the "attachments"
aren't making it. As I said, I'm using the Paperclip plugin, and it
requires a form input with a specific name. I see nothing in Curl
documentation about specifying form attributes. Thoughts as I
continue to read the docs?

..ok, actually I found the information for determining the name of a
form entity. However, it's still not creating the image. Looking at
the logs, it's inserting NULL data during the post. I'm not sure if
the file isn't making it or if the application is simply mishandling
it.

...hrm.

And there's no other complaints in the logs? What web server are
you using? Does it have a way to turn up the verbosity of logging?

Do you have WireShark or some other wire-level monitor available?
Sounds like time to watch the actual traffic coming into your server.

First and foremost: Thank you guys so much for your help. I actually
figured out what to do. I had to make the name of the POSTed file
item "Filedata". Keep in mind this is only so because I'm also using
a function called swfupload_file (name isn't important so much as what
it does) on the site as well. That allowed me to circumvent the
direct Paperclip confusion and route it through as if I were using
swf_upload itself. Anyway, the function looks like this:

  def swfupload_file=(data)
    data.content_type =
MIME::Types.type_for(data.original_filename).to_s
    self.avatar = data
  end

This, in combination with the mimetype gem allowed me to properly
generate the file. I'm sure there are a few items I'm missing, but oh
well.

Thanks again!