Skip to content

Instantly share code, notes, and snippets.

@billdawson
Created May 3, 2011 01:18
Show Gist options
  • Save billdawson/952659 to your computer and use it in GitHub Desktop.
Save billdawson/952659 to your computer and use it in GitHub Desktop.
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
});
// Open an output stream for a file
// to hold the blob data.
var f =
Titanium.Filesystem.getFile(
Titanium.Filesystem.applicationDataDirectory, "out.jpg");
var outstream = f.open(Titanium.Filesystem.MODE_WRITE);
// 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) {
outstream.write(buffer, 0, read_bytes);
}
// Cleanup.
instream.close();
outstream.close();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment