Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download progress & js #51

Open
xgqfrms opened this issue Oct 8, 2018 · 15 comments
Open

download progress & js #51

xgqfrms opened this issue Oct 8, 2018 · 15 comments
Labels
download progress & js download progress & js fetch api & image fetch api & image Fetch & GET & POST & Content-Type & Query String Fetch & GET & POST & Content-Type & Query String Fetch & GET & POST Fetch & GET & POST Fetch & POST & JSON Server Fetch & POST & JSON Server Fetch & uplaod file Fetch & uplaod file FormData & Fetch FormData & Fetch

Comments

@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 8, 2018

JakeChampion/fetch#89

https://stackoverflow.com/questions/35711724/upload-progress-indicators-for-fetch
https://stackoverflow.com/questions/36453950/upload-file-with-fetch-api-in-javascript-and-show-progress

https://developer.mozilla.org/zh-CN/docs/Web/API/Response/status
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

function consume(stream, total = 0) {
    while (stream.state === "readable") {
        var data = stream.read();
        total += data.byteLength;
        console.log("received " + data.byteLength + " bytes (" + total + " bytes in total).");
    }
    if (stream.state === "waiting") {
        stream.ready.then(() => consume(stream, total));
    }
    return stream.closed;
}

fetch("https://cdn.xgqfrms.xyz/json/data.json")
.then(res => consume(res.body))
.then(() => console.log("consumed the entire body without keeping the whole thing in memory!"))
.catch((e) => console.error("something went wrong", e));

https://davidwalsh.name/fetch

@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 8, 2018

@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 8, 2018

axios & progress

https://github.com/axios/axios
https://github.com/axios/axios#request-config

{
  // `onUploadProgress` allows handling of progress events for uploads
  onUploadProgress: function (progressEvent) {
    // Do whatever you want with the native progress event
  },

  // `onDownloadProgress` allows handling of progress events for downloads
  onDownloadProgress: function (progressEvent) {
    // Do whatever you want with the native progress event
  },
}

@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 8, 2018

"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 *
 * @description Fetch & Streams API & Progress Indicator Examples
 * @link https://github.com/xyz-data/fetch-progress-indicators
 * @augments
 * @example fetchProgress();
 *
 */

const fetchProgress = (url = `https://cdn.xgqfrms.xyz/json/data.json`, debug = false) => {
    const streamConsume = (stream, total = 0) => {
        while (stream.state === "readable") {
            let data = stream.read();
            total += data.byteLength;
            console.log(`received ${data.byteLength} bytes; (${total} bytes in total).`);
        }
        if (stream.state === "waiting") {
            stream.ready.then(() => consume(stream, total));
        }
        return stream.closed;
    };
    fetch(url)
    .then(res => streamConsume(res.body))
    .then(() => console.log("consumed the entire body without keeping the whole thing in memory!"))
    .catch((e) => console.error("something went wrong", e));
};

export default fetchProgress;

export {
    fetchProgress,
};

image

@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 8, 2018

wangEditor

基于 javascript 和 css 开发的 Web富文本编辑器, 轻量、简洁、易用、开源免费

http://www.wangeditor.com/index.html
https://github.com/wangfupeng1988/wangEditor/

https://www.kancloud.cn/wangfupeng/wangeditor3/335769

$ npm i -S wangeditor
var E = window.wangEditor;
var editor = new E('#div1');
editor.create();

https://github.com/wangfupeng1988/wangEditor/blob/master/example/demo/in-react/src/App.js

// React refs

image


https://github.com/wangfupeng1988/wangEditor/issues/1746

https://codepen.io/webgeeker/pen/EdNoEJ

@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 8, 2018

image

$ npm audit
$ npm audit fix

https://nodesecurity.io/advisories/328

@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 8, 2018

Repository owner locked and limited conversation to collaborators Oct 8, 2018
@xgqfrms xgqfrms added the download progress & js download progress & js label Oct 8, 2018
@xgqfrms
Copy link
Owner Author

xgqfrms commented Oct 8, 2018

Chinese character bug

中文乱码 & UTF-8

image

@xgqfrms
Copy link
Owner Author

xgqfrms commented Mar 1, 2019

FormData

https://www.raymondcamden.com/2016/05/10/uploading-multiple-files-at-once-with-fetch/

function processForm(e) {
    e.preventDefault();
    
    var formData = new FormData();
    if($f1.val()) {
        var fileList = $f1.get(0).files;
        for(var x=0;x<fileList.length;x++) {
            formData.append('file'+x, fileList.item(x));    
        }
    }

    fetch('http://localhost:3000/upload', {
        method:'POST',
        body:formData   
    }).then(function(res) {
        console.log('Status', res);
    }).catch(function(e) {
        console.log('Error',e);
    });
    
}

@xgqfrms
Copy link
Owner Author

xgqfrms commented Mar 1, 2019

@xgqfrms xgqfrms added FormData & Fetch FormData & Fetch Fetch & uplaod file Fetch & uplaod file fetch api & image fetch api & image Fetch & POST & JSON Server Fetch & POST & JSON Server Fetch & GET & POST & Content-Type & Query String Fetch & GET & POST & Content-Type & Query String Fetch & GET & POST Fetch & GET & POST labels Mar 1, 2019
@xgqfrms xgqfrms pinned this issue Mar 1, 2019
@xgqfrms
Copy link
Owner Author

xgqfrms commented Mar 18, 2020

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
download progress & js download progress & js fetch api & image fetch api & image Fetch & GET & POST & Content-Type & Query String Fetch & GET & POST & Content-Type & Query String Fetch & GET & POST Fetch & GET & POST Fetch & POST & JSON Server Fetch & POST & JSON Server Fetch & uplaod file Fetch & uplaod file FormData & Fetch FormData & Fetch
Projects
None yet
Development

No branches or pull requests

1 participant