cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
193
Views
0
Helpful
0
Comments
cdnadmin
Level 11
Level 11
This document was generated from CDN thread

Created by: Vinay Kanakath on 11-02-2013 09:08:27 AM
Hello, I need to upload an image to Cisco WebExSocial Server, when i tried to upload i am getting 500 Internal server, I think problem is setting and sending the parameters, I tried so many ways but getting the same exception, can anybody help me to resolve this issue, Thanks In Advance..
here is the sample request data given by the WebEx Api: POST /api/quad/rest/users/@me/images/@profile]http://quadserver]/api/quad/rest/users/@me/images/@profile accept: application/json content-length: 87899 expect: 100-continue content-type: multipart/form-data; boundary=----------------------------02a4bb521c19 ------------------------------02a4bb521c19 Content-Disposition: form-data; name="file"; filename="ProfilePhoto.jpg" <binary_file> ------------------------------02a4bb521c19--
Code what I written is:
@RequestMapping (value="/uploadimage", method=RequestMethod.POST)
public @ResponseBody void imageUpload(HttpServletRequest request) throws IllegalStateException, UnsupportedEncodingException, OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException {
HttpURLConnection conn = null;
DataOutputStream dos = null;
DataInputStream inStream = null;
String lineEnd ="\r\n"; String twoHyphens = "--";
String boundary = "AaB03x87yxdkjnxvi7";
int bytesRead, bytesAvailable, bufferSize; byte[] buffer;
int maxBufferSize = 1 * 1024 * 1024;
OAuthUtil util=new OAuthUtil();
// Calling The Server program To Esablish Connection....
provconsum=util.AddConsumer(provider, consumer,provconsum,
request, imageController);
String urlString = http://bac-quad-01.bankofamerica.com/quadopen/api/rest/users/@me/images/@profile;
try {
// ------------------ CLIENT REQUEST
FileInputStream fileInputStream = new FileInputStream(new File( "C:\\Users\\ZKTJQXR\\Downloads\\img.jpg"));
// open a URL connection to the Servlet
URL url = new URL(urlString);
// Open a HTTP connection to the URL
conn = (HttpURLConnection) url.openConnection();
// Allow Inputs
conn.setDoInput(true);
// Allow Outputs
conn.setDoOutput(true);
// Don't use a cached copy.
conn.setUseCaches(false);
// Use a post method.
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
conn.setRequestProperty("image_to_upload", "C:\\Users\\ZKTJQXR\\Downloads\\img.jpg");
System.out.println(" Before Sign Method Call...");
consumer.sign(conn);
System.out.println(" After Sign method.....");
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data;
name=\"image_to_upload\";filename=\"" +"\"C:\\Users\\ZKTJQXR\\Downloads\\img.jpg\"" + lineEnd);
dos.writeBytes(lineEnd); dos.writeBytes(lineEnd);
// create a buffer of maximum size
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte;
// 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);
fileInputStream.close(); dos.flush(); dos.close();
} catch (MalformedURLException ex) { ex.printStackTrace();
} catch (IOException ioe) { System.out.println("Server Response Is: ");
ioe.printStackTrace(); }
// ------------------ read the SERVER RESPONSE
try {
inStream = new DataInputStream(conn.getInputStream());
String str;
while ((str = inStream.readLine()) != null)
{
System.out.println("Sever Response Is: "+str);
}
inStream.close();
} catch (IOException ioex)
{ System.out.println("Server Response Is: "); ioex.printStackTrace(); } } 

Subject: RE: Upload Image To The Cisco WebEx Social Server
Replied by: Adrienne Moherek on 13-02-2013 04:54:00 PM
Hi Vinay,

Try changing this:
name=\"image_to_upload\"
to this:
name=\"file\"
Thanks,
Adrienne
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links