Hello,
I am building an iOS app using the latest SDK (2.1.1) and I need to upload a photo from the app to the backend which is built on Rails and uses the Paperclip gem. This upload works fine with a CURL command in the terminal but not from the app itself.
I am sending along the photo but Rails does not see it.
I am using this header and I tried with a multipart too but still no upload
httpClient.setRequestHeader ("content-type", "application/json");
1 Answer
HI Daniel
I do not know anything about rails - but if it accepts files in the same way as a standard web page with a file input tag does then you need to change the header.
Setting application/json tells the receiving end to expect json, but you are sending file data. You need to use multipart/form-data instead, which is form input fields and file inputs.
httpClient.setRequestHeader("Content-type", "multipart/form-data;");You would then include your files in the send parcel like this;
... httpClient.setRequestHeader("Content-type", "multipart/form-data;"); ... var param = { firstname: 'some', lastname: 'one', file53: image.getImage() // this is a ref to the image/file data - not a filename }; ... httpClient.send(param);You can have more than one file send and the name
file53 is anything you want. XHR will sort the rest for you.
Your Answer
Think you can help? Login to answer this question!