in Education by
I'm developing an Android app and I'm working on photo uploading to my rails server. If I upload ad image from browser, server gives me this (I'm using paperclip gem to upload): COMMIT CODE [...] , "immagine"=># , @original_filename="24e14f4a46269f89ace12297b9ed4060aa3b44f5.jpeg">, [...] My question is: how can I use multipart to upload correctly? On android, working with json objects I used: HttpPost post = new HttpPost("http://10.0.2.2:3000/segnalaziones?format=json"); JSONObject eventObj = new JSONObject(); JSONObject holder = new JSONObject(); try { // Genero l'oggetto JSON eventObj.put("categoria1", c1); eventObj.put("categoria2", c2); eventObj.put("categoria3", c3); eventObj.put("descrizione", descr); eventObj.put("dove", coord); eventObj.put("mood", mood); eventObj.put("via", via); //eventObj.put("android", android); holder.put("commit", "Spedisci"); holder.put("segnalazione", eventObj); Log.e("Event JSON", "Event JSON = "+ holder.toString()); StringEntity richiesta = new StringEntity(holder.toString()); post.setEntity(richiesta); post.setHeader("Content-Type","application/json"); UPDATE I've tried HttpPost post = new HttpPost("http://10.0.2.2:3000/segnalaziones"); MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); multipartEntity.addPart("commit", new StringBody("Spedisci")); multipartEntity.addPart("segnalazione[immagine]", new FileBody(photo)); post.setEntity(multipartEntity); HttpResponse response = client.execute(post); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { resEntity.consumeContent(); } .. but in this case server receives well but doesn't "insert into". Please look at the screens ... This screen is the post from browser ... all goes well http://imageshack.us/photo/my-images/219/brozk.png/ This from android ... no "insert into" ... WHY?? http://imageshack.us/photo/my-images/13/andvv.png/ NOTE THAT if I send the same post without adding an image ... "INSERT INTO" works JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
here is a nice article link. This helped me to upload image from android device to server. I hope it will also help to you.

Related questions

0 votes
    i have this problem that i want to upload image on a server through multi-part form but its keep ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    i have this problem that i want to upload image on a server through multi-part form but its keep ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    in my app i want to upload an image chosen via UIImagePickerController to a database which only accepts JPEG ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 16, 2022 in Education by JackTerrance
0 votes
    Which method facilitates in uploading a Blob to a server? (a) send() (b) pass() (c) upload() ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 21, 2021 in Education by JackTerrance
0 votes
    I am trying to build a Rails 3.1 app in which users can preview individual pages of documents or ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 30, 2022 in Education by JackTerrance
0 votes
    I am completely new with Android/Eclipse. I can't figure out how to add an image in the /res/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I am completely new with Android/Eclipse. I can't figure out how to add an image in the /res/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I am working on my first Android Application. What I am trying to do is a POST request to a REST ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    So i want to save the RelativeLayout (360x360dp) into the phone as a picture. Here is the code ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    How to remove a image in imageview in android and also how to hide the entire image. Here I have ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 27, 2022 in Education by JackTerrance
0 votes
    I'm trying to overlay 2 ImageViews, one with the background and one with an animated (using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I'm trying to overlay 2 ImageViews, one with the background and one with an animated (using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    In our application, we need to transfer video, we are using Camera class to capture the buffer and send ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 15, 2022 in Education by JackTerrance
0 votes
    I'm using the following in the web page but can't get a response from the server while it's ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I'm using the following in the web page but can't get a response from the server while it's ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
...