ダウンロード
Object Body のダウンロードは、KiiObject の取得とは別のタイミングで行います。KiiObject 取得の時点ではダウンロードは行われません。Object Body のダウンロードには XMLHttpRequest Level 2, FileReader
および Blob
のサポートが必要です。
JavaScript SDK の v2 系では、progress コールバックによるダウンロード進捗状況の確認ができます。
(SDK v3 系ではコールバック自体が未サポートのため、この機能は利用できません)
Server Code では Object Body のダウンロードが利用できません。
KiiObject の Object Body をダウンロードする例を以下に挙げます。
-
// Instantiate the target KiiObject. var object = KiiObject.objectWithURI('Set the URI of an existing KiiObject here'); // Start downloading. object.downloadBody().then( function(params) { var theObject = params[0]; var bodyBlob = params[1]; var contentType = bodyBlob.type; // Do something. // The object body is downloaded as bodyBlob. // The type attribute contains the content type managed in Kii Cloud. // object.getBodyContentType() returns the same type; } ).catch( function(error) { var theObject = error.target; var errorString = error.message; // Handle the error. } );
-
// Instantiate the target KiiObject. var object = KiiObject.objectWithURI('Set the URI of an existing KiiObject here'); // Start downloading. object.downloadBody({ progress: function (oEvent) { if (oEvent.lengthComputable) { var percentComplete = oEvent.loaded / oEvent.total * 100; // Get the download progress. You can update the progress bar with this function. } } }).then( function(params) { var theObject = params[0]; var bodyBlob = params[1]; var contentType = bodyBlob.type; // Do something. // The object body is downloaded as bodyBlob. // The type attribute contains the content type managed in Kii Cloud. // object.getBodyContentType() returns the same type; } ).catch( function(error) { var theObject = error.target; var errorString = error.message; // Handle the error. } );
-
// Instantiate the target KiiObject. var object = KiiObject.objectWithURI('Set the URI of an existing KiiObject here'); // Start downloading. object.downloadBody({ progress: function (oEvent) { if (oEvent.lengthComputable) { var percentComplete = oEvent.loaded / oEvent.total * 100; // Get the download progress. You can update the progress bar with this function. } }, success: function(theObject, bodyBlob) { // Do something. // The object body is downloaded as bodyBlob. // The type attribute contains the content type managed in Kii Cloud. // object.getBodyContentType() returns the same type; var contentType = bodyBlob.type; }, failure: function(theObject, errorString) { // Handle the error. } });
(SDK v2 系のみ)progress コールバックが転送の進捗状況に応じて呼び出されます。転送サイズが小さい場合は、1 回目の呼び出しで 100% の進捗を示すことがあります。