SQLの窓

2012年05月23日


Windows8 で SkyDrive にアップロードするサンプル


起動後の画面です。サインインを実行してからアップロードボタンをクリックしてアップロードするファイルを選択します



まずはサインイン





サインインが完了したのでメッセージを表示しています。
( ここまでで、▲ リンク先と同じです )



▲ アップードボタンをクリックすると、▼ に画面が切り替わります。





ファイルを選択し終わりましたので、『開く』でアップロードが開始されます。終了メッセージの表示を実装していないので、Debug.writeln の結果で確認します。







<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta charset="utf-8">
    <title>SkyApp</title>

    <!-- WinJS references -->
    <link href="//Microsoft.WinJS.0.6/css/ui-dark.css" rel="stylesheet">
    <script src="//Microsoft.WinJS.0.6/js/base.js"></script>
    <script src="//Microsoft.WinJS.0.6/js/ui.js"></script>

    <script src="///LiveSDKHTML/js/wl.js"></script>

    <!-- SkyApp references -->
    <link href="/css/default.css" rel="stylesheet">
    <script src="/js/default.js"></script>
</head>
<body style="padding: 30px;">
    <h1>Sky Drive アップロードサンプル</h1>
    <div id="signin" style="margin-bottom: 20px;margin-top: 20px;"></div>
    <button id="upload" style="width:112px;background-color:skyblue;color:black;">アップロード</button>
    <br />
    <label id="info"></label>
    <script>

        document.getElementById("upload")
            .addEventListener("click", function () { uploadFile('me/skydrive/my_photos'); }, false);

        WL.Event.subscribe("auth.login", onLogin);
        WL.init({
            scope: ["wl.signin", "wl.basic", "wl.skydrive_update"]
        });
        WL.ui({
            name: "signin",
            element: "signin"
        });
        function onLogin() {
            WL.api({
                path: "me",
                method: "GET"
            }).then(
                function (response) {
                    document.getElementById("info").innerText =
                        "Hello, " + response.first_name + " " + response.last_name + "!";
                    
                },
                function (responseFailed) {
                    document.getElementById("info").innerText =
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        }

        function uploadFile(path) {
            setupOpenPicker().pickSingleFileAsync().then(
                function (file) {
                    if (file) {
                        return WL.upload({ path: path, file_name: file.fileName, file_input: file });
                    } else {
                        Debug.writeln("No file was picked to upload.");
                    }
                }
            ).then(
                function (resp) {
                    if (resp) {
                        Debug.writeln(JSON.stringify(resp,null,"   "));
                    }
                },
                function (error) { Debug.writeln(JSON.stringify(error, null, "   ")) },
                function (progress) { Debug.writeln(JSON.stringify(progress, null, "   ")) }
            );
        }
        function setupOpenPicker() {
            // Required - picker does not work without setting these properties
            var openpicker = new Windows.Storage.Pickers.FileOpenPicker();
            openpicker.fileTypeFilter.replaceAll(["*"]);
            return openpicker;
        }

    </script>
</body>
</html>

my_photos は、Pictures というフォルダが無ければ作成されます。以下のような仕様になっていますが、USER_ID の代わりに me が通常使用されます。USER_ID は、API 等で取得できる数字文字列で、それでもアクセスは可能です。ユーザが作成したフォルダの一覧は、me/skydrive/files で取得できますが、一番上位の階層のみです。 me/skydrive/xxxxx の代わりに、FOLDER_ID を 使ってそのフォルダにアクセス可能です。その下の階層のフォルダ等は、 FOLDER_ID/files で取得します。

例) folder.573059a93afc9e45.573059A93AFC9E45!487/files 

USER_ID/skydrive/camera_roll represents the SkyDrive camera roll folder.
USER_ID/skydrive/my_documents represents the Documents folder.
USER_ID/skydrive/my_photos represents the Pictures folder.
USER_ID/skydrive/public_documents represents the Public folder.




【Windows8 Metro(JS/C#)の最新記事】
posted by lightbox at 2012-05-23 10:59 | Windows8 Metro(JS/C#) | このブログの読者になる | 更新情報をチェックする
container 終わり



フリーフォントで簡単ロゴ作成
フリーフォントでボタン素材作成
フリーフォントで吹き出し画像作成
フリーフォントではんこ画像作成
ほぼ自由に利用できるフリーフォント
フリーフォントの書体見本とサンプル
画像を大きく見る為のウインドウを開くボタンの作成

CSS ドロップシャドウの参考デモ
イラストAC
ぱくたそ
写真素材 足成
フリーフォント一覧
utf8 文字ツール
右サイド 終わり
base 終わり