IOUtils编写器错误Java连接到GAE

时间:2015-04-01 14:06:22

标签: java android google-app-engine io writer

我从apache导入编写器。我尝试使用它时发生错误。

in只是网址。

enter image description here

我正在关注此链接上的内容: Store image to Blobstore from android client and retrieve blobkey and upload url to store in Datastore. - GAE

有人知道这个错误吗?

已更新

以下是完整代码:

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;

import com.google.api.client.util.IOUtils;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

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


public class GetBlobUrlTask extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_get_blob_url_task);
}
@Override
protected Void doInBackground(Void... arg0){

    HttpClient httpClient = new DefaultHttpClient();
    //This will invoke "ImgUpload servlet           
    HttpGet httpGet = new HttpGet("http://PUT_YOUR_URL_HERE/bloburlget");
    HttpResponse response;
    try {
        response = httpClient.execute(httpGet);
        HttpEntity urlEntity = response.getEntity();
        InputStream in = urlEntity.getContent();
        String str = "";
        StringWriter writer = new StringWriter();
        String encoding = "UTF-8";
        IOUtils.copy(in, writer, encoding);
        str = writer.toString();
        HttpPost httppost = new HttpPost(str);
        File f = new File(picturePath);
        MultipartEntityBuilder reqEntity = MultipartEntityBuilder.create();
        reqEntity.addBinaryBody("photo", f, ContentType.create("image/jpeg"), "foto2.jpg");
        httppost.setEntity(reqEntity.build());
        response = httpClient.execute(httppost); //Here "uploaded" servlet is automatically       invoked
        str = EntityUtils.toString(response.getEntity());
        JSONObject resultJson = new JSONObject(str);
        blobKey = resultJson.getString("blobKey");
        servingUrl = resultJson.getString("servingUrl");

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_get_blob_url_task, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

1 个答案:

答案 0 :(得分:0)

我的猜测是示例中的人正在使用IOUtils from Apache Commons而您正在使用其他IOUtils provided by the Google HTTP client