Picalt API

An API is available to 3rd party software developers to integrate their software with Picalt. Integrating is straightforward:
  • Sign-up via Twitter.
  • Grab your email with PIN and add this as the value of the client URL parameter
  • If you have users who want to add to their account rather than post anonymously then they need to sign-up for an email and PIN. This is then added to the user URL parameter
Here is the simple Java code to upload:


    /**
     * Uploads a binary pic to Picalt.com. 'user' and 'client' can be left blank '' if you want to post anonymously
     * @param client is email and PIN of the software used to send - must be in the form Software-12345@picalt.com
     * @param user is the email and PIN of the user - must be in the form Username-12345@picalt.com
     * @param pic is the complete binary image data JPEG/PNG/GIF/BMP
     * @param title is the title of the posting	
     */

public String uploadToPicalt(String client, String user, byte [] pic, String title) {
		
		Socket socket = null;
		StringBuilder sb = new StringBuilder();
	
		try{
			
		      int len = pic.length;

		      URL url  =  
			new URL("http://picalt.com:20005/apps/Picalt2?enc="+java.nio.charset.Charset.defaultCharset().name()
			+"&type=postimage_client&piclen="+len+"&name="+URLEncoder.encode(title)+"&via=PicQuick_client"
			+"&client="+URLEncoder.encode(client)+"&user="+URLEncoder.encode(user));	 		  

		      socket = new Socket(url.getHost(), url.getPort());

		      OutputStream out = socket.getOutputStream();
		      
		      String header = "POST " +url.getFile()+" HTTP/1.0\r\n"
		      	+             "Host: " + url.getHost()+"\r\n"
		      	+	      "User-Agent: "+client+"\r\n"
		      	+             "Content-Length: "+len+"\r\n"
		      	+             "Connection: close\r\n"
		      	+             "\r\n";					      
		      out.write(header.getBytes("UTF-8"));

		     
		      ByteArrayInputStream bin = new ByteArrayInputStream(pic);
		      int c = 0;
		      double done = 0;
		      byte [] b = new byte[4096];

		      while((c=bin.read(b,0,b.length))!=-1){
			    out.write(b,0,c);
			    out.flush(); 
			    done+=c;
			    double pc100 = (done/(double)len)*100;
			    int i100 = (int)pc100;
			    System.out.println("Uploaded "+i100+"%");
		      }
		      		      

		      InputStream in = socket.getInputStream();
		      BufferedReader br  = new BufferedReader(new InputStreamReader(in));
		      String s;
		      boolean parse = false;
		      while((s=br.readLine())!=null){
			 if(parse){
			    sb.append(s);
			 }
		      	 if(s.length()==0){
		      	    parse=true;
		      	 }		      		
		      }


		
		}catch(Throwable t){
			t.printStackTrace();
		}
 		
		
		try{
		    	socket.close();
		}catch(Throwable tt){
			tt.printStackTrace();
		}
		
		//if no error then the URL of the pic at http://picalt.com
		//if an error then string of 0 length
		String url = sb.toString(); 

		return url;
		
}

Any problems, DM us at Twitter.