怎样把图片直接从本地上传到cdn,不需要经过服务器处理?
发布于 7 年前 作者 labike 9175 次浏览 来自 问答

是这样的:今天公司干了12年的php哥,问我怎样直接用富文本编辑器把选择的图片传到cdn上,不需要经过服务器处理。他告诉我淘宝就是这么干的,我比较菜,一时难以理解,如果有知道的请给我讲解一下,谢谢!!!

5 回复

这个是react的,我最近在正好在用 https://github.com/liuhong1happy/react-umeditor 截一下代码,不知道对你有没有用。

getQiniuUploader() {
		return {
			url:'http://upload.qiniu.com',
			type:'qiniu',
			name:"file",
			request: "image_src",
			qiniu:{
				app:{
					Bucket:"",
					AK:"l9vEBNTqrz7H03S-",
					SK:"eizTTxuA0Kq1YSe2SRdOexJ-"
				},
        domain:"http://clouddn.com",
        genKey:function(options){
            return options.file.type +"-"+ options.file.size +"-"+ options.file.lastModifiedDate.valueOf() +"-"+ new Date().valueOf()+"-"+options.file.name;
        }
			}
		}
	}

	render() {
		const icons = this.getIcons()
		const uploader = this.getQiniuUploader()
		const plugins = {
			image:{
				uploader:uploader
			}
		}

		return (
			<div>
				<Editor
					icons={icons}
					plugins={plugins}
					value={this.props.value}
					defaultValue={this.props.defaultValue}
					onChange={this.props.onChange}
				/>
			</div>
		)

谢谢

回到顶部