Git Product home page Git Product logo

image-upload's Introduction

图片上传

包括前端的图片预览、剪裁、上传等及 Node.js 后端对图片的保存,实现整个图片上传逻辑。

知识点

服务端

服务端使用了 Express 4,该版本使用 body-parser 无法处理上传的文件。所以,这里使用了 multiparty 处理图片上传的问题。

图片上传后,需要对图片进行一定的处理,如:压缩、剪裁等,使用的是 Sharp

前端

图片上传前的预览利用了 HTML5 FileReader,读取用户选择要上传的图片,不过该 API 存在兼容性的问题。

图片上传进度利用了 XMLHttpRequest 中的 onprogress 事件,通过 Event 参数中的 loaded 和 total 计算上传百分比。

如何测试

1.克隆仓库并安装依赖

$ git clone https://github.com/hezhii/image-upload.git
$ cd image-upload
$ npm install

2.启动服务

$ npm start

服务默认监听 8080 端口,打开浏览器访问 http://localhost:8080 即可进行测试。

image-upload's People

Contributors

hezhii avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.