I am currently working on a project, that uses Android and Rails. My goal is to write a web-application based on Rails (with RESTful service) that makes it possible for users to post information with their Android mobile phones.
But I have a problem: users should have the possibility to add a picture to their post, unfortunately this doesn’t work so far. I have tried out many ways, but without success.
Any hints or ideas how I can solve this problem? That would be great
. If desired I can post more detailed informations.
Thanks!
ANDROID-CODE:
Using java Syntax Highlighting
- public void httpPostImage() throws Exception {
- HttpClient httpclient = new DefaultHttpClient();
- HttpPost httppost = new HttpPost("http://my-ip/information/add_image");
- File file = new File("/data/data/org.emrah/icon.png");
- InputStreamEntity reqEntity = new InputStreamEntity(
- new FileInputStream(file), -1);
- reqEntity.setContentType("application/x-www-form-urlencoded");
- Header[] headers = new BasicHeader[2];
- headers[0] = new BasicHeader("Accept","application/xml");
- headers[1] = new BasicHeader("Content-type", "application/x-www-form-urlencoded");
- httppost.addHeader(headers[0]);
- httppost.addHeader(headers[1]);
- httppost.setEntity(reqEntity);
- System.out.println("executing request " + httppost.getRequestLine());
- HttpResponse response = httpclient.execute(httppost);
- HttpEntity resEntity = response.getEntity();
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
RAILS-CODE:
- Code: Select all
def add_image
@image = Image.new
@image.blob = params[:image]
@information = Information.find 1
respond_to do |format|
if @image.save
format.xml { render :xml => @information, :status => :created, :location => @information }
else
format.xml { render :xml => @information, :status => :unprocessable_entity }
end
end
end

