I\'m sure this might be a simple question, but unfortunately this is my first time using Java and working the Android SDK.
I am uploading files on Android using the
I was able to figure it out... just had to discover that there's a ByteArrayInputStream that would allow me to convert my byte[] buffer to an InputStream. From here on, I can now track which chunks failed and handle it. Thanks Konstantin for Here's my implementation:
final int chunkSize = 512 * 1024; // 512 kB
final long pieces = file.length() / chunkSize;
int chunkId = 0;
HttpPost request = new HttpPost(endpoint);
BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file));
for (chunkId = 0; chunkId < pieces; chunkId++) {
byte[] buffer = new byte[chunkSize];
stream.skip(chunkId * chunkSize);
stream.read(buffer);
MultipartEntity entity = new MultipartEntity();
entity.addPart("chunk_id", new StringBody(String.valueOf(chunkId)));
request.setEntity(entity);
ByteArrayInputStream arrayStream = new ByteArrayInputStream(buffer);
entity.addPart("file_data", new InputStreamBody(arrayStream, filename));
HttpClient client = app.getHttpClient();
client.execute(request);
}