package xyz.igorgee.shapejs;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class ShapeJS {

    private static final MediaType MEDIA_TYPE_JPG = MediaType.parse("image/jpg");
    private static final String ENDPOINT = "http://52.90.86.247/image";
    public static final String SHAPE_JS_IMAGE_KEY = "shapeJS_img";

    private final OkHttpClient client = new OkHttpClient();

    public InputStream uploadImage(File image) throws IOException {
        RequestBody requestBody = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart(SHAPE_JS_IMAGE_KEY, image.getName(),
                        RequestBody.create(MEDIA_TYPE_JPG, image))
                .build();

        Request request = new Request.Builder()
                .url(ENDPOINT)
                .post(requestBody)
                .build();

        Response response = client.newCall(request).execute();
        return response.body().byteStream();
    }
}

@@ -48,41 +48,8 @@
 le;%0A
-import java.io.FileOutputStream;%0A
 impo
@@ -99,16 +99,54 @@
 tStream;
+%0Aimport java.util.concurrent.TimeUnit;
 %0A%0Aimport
@@ -604,16 +604,92 @@
 tpClient
+.Builder()%0A            .readTimeout(20, TimeUnit.SECONDS)%0A            .build
 ();%0A%0A   
@@ -1224,24 +1224,112 @@
 .execute();%0A
+%0A        if (!response.isSuccessful()) throw new IOException(%22Unsuccessful response%22);%0A%0A
         retu

Increase timeout for intense images