Read Blobs in chunks in Titanium

Posted By : Sapna Sharma | 29-Sep-2015

Sometime while uploading large files we face many issues like out of memory error, timeout error etc. To get rid of these type of errors we should read file(blob) into chunks.

The BlobStream is a read-only stream that provides you with the ability to read blobs in chunks.

Here is an example:

 
Ti.Media.showCamera({
success: function(e) {
// Open stream on blob.
var instream = Titanium.Stream.createStream({
mode: Titanium.Stream.MODE_READ,
source: e.media // e.media is a Blob
});
// Create a buffer for chunking the data.
var buffer = Ti.createBuffer({length: 1024});
// Read and write chunks.
var read_bytes = 0;
while ((read_bytes = instream.read(buffer)) > 0) {
}
// Cleanup.
instream.close();
}
});
 
 

THANKS

About Author

Author Image
Sapna Sharma

Sapna is a bright Android Apps developer using Titanium framework. Sapna likes music and helping needy people.

Request for Proposal

Name is required

Comment is required

Sending message..