簡體   English   中英

contenteditable到javascript中azure存儲中的文本文件

[英]contenteditable to textfile in azure storage in javascript

我正在嘗試將可編輯 div 的內容轉換為文本文件並將其存儲在 azure 中。 它實際上是一個 css 文件(格式),但我想該文本將具有相同的輸出。 這是我到目前為止得到的:\\

var sasKey = "xxxxxxxxxxxxxxx";
var blobUri = xxxxx.blob.core.windows.net";
var blobService = AzureStorage.Blob.createBlobServiceWithSas(blobUri, sasKey);

function Save() {

    var blobData = document.getElementById("CONTENT").innerText;
    var myBlob = new Blob(blobData, "plain/text");

    blobService.createBlockBlobFromBrowserFile('style',
        "test.txt",
        myBlob,
        (error, result) => {
            if (error) {
                // Handle blob error
            } else {    
                console.log('Upload is successful');
            }
        });
}

HTML:

<div id="CONTENT" contenteditable="true" spellcheck="false">so here we have text</div>

<input type="button" value="save" onclick="Save()"/>

我收到以下錯誤:

Uncaught TypeError: Failed to construct 'Blob': The provided value cannot be converted to a sequence.

Blob對象將列表作為其第一個參數。

試試這個:

var myBlob = new Blob([blobData], { type: "plain/text" });

https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob

完成這是我用來上傳文本(txt)文件的內容

<script>azure-storage.blob.min.js</script>

JS

var sasKey = "xxxxxxxxxxxxxxx";
var blobUri = xxxxx.blob.core.windows.net";
var blobService = AzureStorage.Blob.createBlobServiceWithSas(blobUri, sasKey);

function Save() {

    var blobData = document.getElementById("CONTENT").innerText;

    blobService.createContainerIfNotExists('container', (error, container) => {
        if (error) {
            // Handle create container error
        } else {
            console.log(container.name);
        }
    });

    blobService.createBlockBlobFromText('container', "test.txt", blobData,
        (error, result) => {
            if (error) {
                // Handle blob error
            } else {    
                console.log('Upload is successful');
            }
        });
}

HTML

<div id="CONTENT" contenteditable="true" spellcheck="false">so here we have text</div>

<input type="button" value="save" onclick="Save()"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM