1

Uploading image for POI

Тема: Uploading image for POI

Hi everyone

We want to add image for POI using SDK. We are developing an android application. we use below code and server response error 4

FileInputStream fileInputStream = new FileInputStream(sourceFile);
                    URL url = new URL(urlString);

                    // Open a HTTP  connection to  the URL
                    conn = (HttpURLConnection) url.openConnection();
                    conn.setDoInput(true); // Allow Inputs
                    conn.setDoOutput(true); // Allow Outputs
                    conn.setUseCaches(false); // Don't use a Cached Copy
                    conn.setRequestMethod("POST");

                    conn.setRequestProperty("Connection", "Keep-Alive");
                    conn.setRequestProperty("Host", "hst-api.wialon.com");
                    conn.setRequestProperty("Cache-Control", "no-cache");
                    conn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
                    conn.setRequestProperty("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.3");
                    conn.setRequestProperty("Accept-Encoding", "gzip,deflate,sdch");
                    conn.setRequestProperty("Accept-Language", "ru,en-US;q=0.8,en;q=0.6");
                    dos = new DataOutputStream(conn.getOutputStream());
                    dos.writeBytes(twoHyphens + boundary + lineEnd);
                    dos.writeBytes("Content-Disposition: form-data; name=\"params\"\n" +
                            "\n" +lineEnd+lineEnd+
                            "{\"itemId\":"+id+",\"poiId\":"+poiid+",\"eventHash\":\"jUploadForm1372768029714\"}"
                             + "\"" + lineEnd);
                    dos.writeBytes(twoHyphens + boundary + lineEnd);
                    dos.writeBytes("Content-Disposition: form-data; name=\"eventHash\""+lineEnd+lineEnd+"jUploadForm1372768029714");
                    dos.writeBytes(twoHyphens + boundary + lineEnd);
                    dos.writeBytes("Content-Disposition: form-data; name=\"poi_dlg_props_upload_image\"; filename=\"zZeVUgLEJXE.jpg\"");
                    dos.writeBytes(lineEnd);
                    dos.writeBytes("Content-Type: image/jpeg"+lineEnd+lineEnd);
                    dos.writeBytes(twoHyphens + boundary + lineEnd);

                    // create a buffer of  maximum size
                    bytesAvailable = fileInputStream.available();

                    bufferSize = Math.min(bytesAvailable, maxBufferSize);
                    buffer = new byte[bufferSize];

                    // read file and write it into form...
                    bytesRead = fileInputStream.read(buffer, 0, bufferSize);

                    while (bytesRead > 0) {

                        dos.write(buffer, 0, bufferSize);
                        bytesAvailable = fileInputStream.available();
                        bufferSize = Math.min(bytesAvailable, maxBufferSize);
                        bytesRead = fileInputStream.read(buffer, 0, bufferSize);

                    }

                    // send multipart form data necesssary after file data...
                    dos.writeBytes(lineEnd);
                    dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

                    // Responses from the server (code and message)
                    serverResponseCode = conn.getResponseCode();
                    String serverResponseMessage = conn.getResponseMessage();

Any one can help us and explain what's wrong with our code ))) ?
Consider that we create POI in our app and then in this step we get error 4. some inputs in the codes comes from previous step of creating POI.

Thank you all!

2

Uploading image for POI

Re: Uploading image for POI

dear partners

Issue solved!