Android FileEntity - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android FileEntity class.

This code example shows how to use the following methods:
         
        // See related encoding change in DropboxDownloadHelper. 
        String url = FILE_UPLOAD_URL + URLEncoder.encode(fileName, "UTF-8").replace("+", "%20");
        HttpPost httppost = new HttpPost(url);
        httppost.addHeader("Authorization", headerValue);
        httppost.setEntity(new FileEntity(new File(filePath), "application/x-sqlite3"));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        if(response.getStatusLine().getStatusCode() == 200 && resEntity != null){
            InputStream is = resEntity.getContent();
            JSONObject jsonResponse = new JSONObject(IOUtils.toString(is));
            if(jsonResponse.getString("modified") != null){
                is.close();
                return true; 
            } 
        } 
        return false; 
    }; 
     
} 
5
CodeRank
This code example shows how to use the following methods:setContentType
This code example shows how to use the following methods:
                    System.out.println("Cannot read file " + file.getPath()); 
 
                } else { 
 
                    response.setStatusCode(HttpStatus.SC_OK); 
                    FileEntity body = new FileEntity(file, "text/html");
                    response.setEntity(body); 
                    System.out.println("Serving file " + file.getPath()); 
 
                } 
            } 
        } 
         
        private String thriftRequest(byte[] input){
            try{ 
             
                //Input 
                TMemoryBuffer inbuffer = new TMemoryBuffer(input.length);           
                inbuffer.write(input);              
                TProtocol  inprotocol   = new TJSONProtocol(inbuffer);                   
5
CodeRank
This code example shows how to use the following methods:
                System.out.println("Cannot read file " + file.getPath()); 
                 
            } else { 
                 
                response.setStatusCode(HttpStatus.SC_OK); 
                FileEntity body = new FileEntity(file, "text/html");
                response.setEntity(body); 
                System.out.println("Serving file " + file.getPath()); 
                 
            } 
        } 
         
    } 
     
    static class EventLogger implements EventListener {
 
        public void connectionOpen(final NHttpConnection conn) {
            System.out.println("Connection open: " + conn);
        } 
 
4
CodeRank
This code example shows how to use the following methods:
	    HttpPost httpPost = new HttpPost(url);
	    HttpResponse response = null;
 
	    FileEntity tmp = null;       
 
	    tmp = new FileEntity(data,"UTF-8");
 
	    httpPost.setEntity(tmp);
 
	    try { 
	        response = httpclient.execute(httpPost);
	    } catch (ClientProtocolException e) {
	    	Log.e("WATCHER", "HTTPHelp : ClientProtocolException : "+e);
	    } catch (IOException e) {
	    	Log.e("WATCHER", "HTTPHelp : IOException : "+e);
	    } 
 
        return response.getStatusLine().getStatusCode();
	} 
} 
4
CodeRank
This code example shows how to use the following methods:setContentEncoding
			 
			URI uri = new URI(url);
			 
			httppost = new HttpPost(uri);
			 
			FileEntity fe = new FileEntity(new File(filepath), "image/jpeg");
			 
			fe.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "image/jpeg"));
			 
			httppost.setEntity(fe);
			 
			httppost.addHeader("Authorization", "Bearer " + token);
			 
			httppost.addHeader("GData-Version", "2");
							 
			ResponseHandler<String> res = new BasicResponseHandler();
			 
			String httpResponseUpload = client.execute(httppost, res);
			 
			Log.i(TAG, "Response from Upload: " + httpResponseUpload);
4
CodeRank
This code example shows how to use the following methods:
    public Request bodyString(final String s, final ContentType contentType) {
        return body(new StringEntity(s, contentType));
    } 
 
    public Request bodyFile(final File file, final ContentType contentType) {
        return body(new FileEntity(file, contentType));
    } 
 
    public Request bodyByteArray(final byte[] b) {
        return body(new ByteArrayEntity(b));
    } 
 
    public Request bodyByteArray(final byte[] b, int off, int len) {
        return body(new ByteArrayEntity(b, off, len));
    } 
 
    public Request bodyStream(final InputStream instream) {
        return body(new InputStreamEntity(instream, -1));
    } 
 
3
CodeRank
This code example shows how to use the following methods:
	} 
	 
	public static HttpEntity createFileEntity(String filePath){
		 
		File image = new File(filePath);
		FileEntity fileEntity = new FileEntity(image, "application/octet-stream");
		return fileEntity;
		 
//		MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 
//		FileBody fileBody = new FileBody(image, filePath, "images/jpeg"); 
//		if (fileBody.getContentLength() == 0){ 
//			return null; 
//		} 
//		entity.addPart("image", fileBody); 
//		return entity; 
	} 
} 
4
CodeRank
This code example shows how to use the following methods:
	} 
 
	private static FileEntity createFileEntity(final String filePath, final String contentType) {
 
		File file = new File(filePath);
		FileEntity fileEntity = new FileEntity(file, contentType);
		return fileEntity;
	} 
 
	private static Header[] createHeaders() {
 
		return new Header[] {
				new BasicHeader("Accept-Charset", "UTF-8"),
				new BasicHeader("DataServiceVersion", "1.0;NetFx"),
				new BasicHeader("MaxDataServiceVersion", "2.0;NetFx"),
				new BasicHeader("Accept", "application/json;odata=verbose"),
				new BasicHeader("Host", "localhost"),
				new BasicHeader("Expect", "100-continue"),
				new BasicHeader("User-Agent",
						"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2") }; 
3
CodeRank
This code example shows how to use the following methods:

Related Android FileEntity Questions & Answers:

See Code Examples for Android FileEntity Methods: