Created
November 26, 2016 11:17
-
-
Save ccd97/e9ec4e3ffabc273cf17d3da342235d05 to your computer and use it in GitHub Desktop.
Testing TensorflowServer API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Place /lib in same dir with .jar files(can be downloaded from maven): | |
1) httpmime-*.jar | |
2) httpcore-*.jar | |
3) httpclient-*.jar | |
4) commons-logging-*.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.http.HttpEntity; | |
import org.apache.http.HttpResponse; | |
import org.apache.http.client.HttpClient; | |
import org.apache.http.client.methods.HttpPost; | |
import org.apache.http.entity.ContentType; | |
import org.apache.http.entity.mime.HttpMultipartMode; | |
import org.apache.http.entity.mime.MultipartEntityBuilder; | |
import org.apache.http.impl.client.HttpClientBuilder; | |
import org.apache.http.util.EntityUtils; | |
import java.io.File; | |
import java.io.IOException; | |
import java.security.NoSuchAlgorithmException; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
String imageFileName = "/home/cyprien/Downloads/New/Test/garbage.jpeg"; | |
String serverUrl = "https://deepblue-tensorflow.herokuapp.com/classify_image/classify/"; | |
HttpClient client = HttpClientBuilder.create().build(); | |
HttpPost post = new HttpPost(serverUrl); | |
File file = new File(imageFileName); | |
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); | |
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); | |
builder.addBinaryBody | |
("image", file, ContentType.DEFAULT_BINARY, imageFileName); | |
HttpEntity entity = builder.build(); | |
post.setEntity(entity); | |
HttpResponse response = client.execute(post); | |
HttpEntity responseEntity = response.getEntity(); | |
System.out.println(EntityUtils.toString(responseEntity)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
javac -cp ".:lib/*" Main.java | |
java -classpath ".:lib/*" Main | |
rm *.class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment