Alright, this is going to be a little difficult to explain, so please bear with me...
I have a Rails app that encompasses a large javascript codebase written for the ESRI ArcGIS javascript API to interact with spatial data stored on an ESRI ArcGIS Server. The ESRI ArcGIS javascript API uses something that's commonly referred to as an "ArcGIS Server proxy" to forward requests to a ArcGIS Server Service that requires token-based authentication or are too long to be handled directly within the URL. The AGS proxy simply makes an HTTP request to a URL that's passed to it, forwarding any additional parameter that's passed along with the original request to the ArcGIS Server Service, which does the actual heavy lifting and responds with JSON. For more information regarding the AGS proxy, please refer to the following page on the ArcGIS Resource Center.
Given that the AGS proxy is only provided by ESRI in ASP.Net, Java and PHP flavors, I've taken the liberty of writing an AGS proxy as a Rails controller. I've opted to take this approach because the JSAPI doesn't support cross-domain requests and for hosting reasons I don't want to serve PHP within my Rails app or run my app on top of JRuby. My Rails AGS proxy works in all circumstances I've encountered so far except for multipart requests, which occur with the Attachment Editor functionality, which is illustrated here.
In my attempts at making multipart requests work, I've opted to use Faraday for making HTTP requests to the ArcGIS Server Service because of Faraday's simplicity and support for multipart requests. My code that attempts to do multipart requests is as follows:
# Configure the request
uri = URI.parse(url)
conn = Faraday.new(:url => ("http://" + uri.host.downcase)) do |faraday|
faraday.request :multipart
faraday.request :url_encoded
faraday.response :logger
faraday.adapter Faraday.default_adapter
end
# Make request
response = conn.post uri.path do |req|
req.body = agsparams
end
The "agsparams" variable is a hash of parameters that's being passed to ArcGIS Server.
When attempting to execute this code, Ruby errors on the line where the actual request is being made with the following error, which is where I'm currently stuck:
NoMethodError (undefined method `local_path' for #ActionDispatch::Http::UploadedFile:0x007ffbe198fe60
When I dump the params hash in the controller, it looks similar to the following:
{
"attachment"=>#ActionDispatch::Http::UploadedFile:0x007ffbe198fe60
@original_filename="test_image.jpg",
@content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"attachment\"; filename=\"test_image.jpg\"\r\nContent-Type: image/jpeg\r\n",
@tempfile=#File:/var/folders/mh/2mfy5nr54gngrzg06gzp1jcw0000gn/T/RackMultipart20120718-2772-xwbgjy,
"f"=>"json",
"http://arcgisserver.com/arcgis/rest/services/multitenant/test_organization/FeatureServer/0/4808/addAttachment"=>nil
}
(I removed some brackets so that this will display on StackOverflow.)
I don't know where the "local_path" method is being called as I'm not calling it but my guess is that this is some sort of built-in functionality that's associated with ActionDispatch that I don't understand. Is there a method in ActionDispatch that I need to override, if so, how do I do that? I have a hunch that ActionDispatch is making an attempt at uploading the file that I specify when I really just want to forward the file input parameters to ArcGIS Server so that ArcGIS Server does the upload. I don't think I want to use Faraday::UploadIO as I think I just need to forward parameters to ArcGIS Server, but I could be wrong. Where do I go from here??
As some additional due-diligence I've confirmed that my mapping javascript works with other flavors of the AGS proxy; I've also inspected working multipart proxy requests with Wireshark and have compared those requests with requests being made with my Rails AGS proxy and they seem consistent (the headers and params look right). The data that I'm attempting to add attachments to is in fact configured properly to accept attachments. I'm stuck and really could use some help.
A little about my environment: My app is written in Rails 3.2 on Ruby 1.9.2 (I currently use CarrierWave and Fog to handle attachments on other non-mapping parts of the app, if that matters at all). I'm attempting to post through ArcGIS JSAPI 2.8/Dojo 1.6 to a server running ArcGIS Server 10.1.
Thanks in advance...