0

URL から入力ストリームを作成し、画像を Facebook に正常にアップロードできます。

HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
int length = conn.getContentLength();
imgData = new byte[length];
InputStream is = conn.getInputStream();

しかし、私はバンドルからInputstreamを取得しています-

Bundle extras = getIntent().getExtras();
if (extras != null) {
    int img_pos = extras.getInt("image_pos");
    mInputStream = com.LiveWallapper.LiveWallapperActivity.mInput.get(img_pos);
    System.out.println("input in readbytes++++++++++++++" + mInputStream);
}

Example.java のような画像をアップロードしたい -

params.putString("method", "photos.upload");
params.putByteArray("picture", readBytes(mInputStream));
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);

readBytes メソッドは --

public byte[] readBytes(InputStream inputStream) throws IOException {
    // this dynamically extends to take the bytes you read
    ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
    // this is storage overwritten on each iteration with bytes

    // we need to know how may bytes were read to write them to the
    // byteBuffer

    int bufferSize = 10000;//i can not getcontent length from inputstream so i give //10000, pls help
    byte[] imgData = new byte[bufferSize];
    int len = 0;

    while ((len = inputStream.read(imgData)) != -1) {
        byteBuffer.write(imgData, 0, len);
    }

    // and then we can return your byte array.
    return byteBuffer.toByteArray();
}
4

0 に答える 0