javascript - 将图像转换为 blob 以存储在 phpmyadmin 中
问题描述
我有一个反应应用程序,它有一个基本的注册页面,其中一部分是允许用户上传个人资料照片。我在这里阅读了很多关于在服务器端发送图像的答案,但没有一个对我有用。为了克服C:\\fakepath\\img-name
. 有没有办法让我将图像转换为缓冲数组以与我的其他输入字段一起发送?
这是我将数据发送到我的 api 的方式:
handleSubmit(){
let fname = this.state.fname;
let lname = this.state.lname;
let email = this.state.email;
let password = this.state.password;
let mentor = this.state.mentor;
let mentee = this.state.mentee;
let photo = this.state.photo
let interest1 = this.state.interest1;
let interest2 = this.state.interest2;
let interest3 = this.state.interest3;
let course = this.state.course;
const requestBody = {
fname: fname,
lname: lname,
email: email,
password: password,
photo: photo,
mentor: mentor,
mentee: mentee,
interest1: interest1,
interest2: interest2,
interest3: interest3,
course: course
}
const config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}}
if(this.checkValidation()) {
request.post("/register",qs.stringify(requestBody),config)
.then(result => this.setState({submitStatus: result.status}))
.catch(err => console.log(err))
}
}
当我将它提交到我的 api 服务器时,我得到了这个:
{ fname: 'Naruto',
lname: 'Uzumaki',
email: 'Naruto@konoha.com',
password: 'Hokage',
mentor: 'on',
mentee: '',
interest1: 'Anime',
interest2: 'Football',
interest3: 'Gaming',
course: 'CPSS' }
任何有关这方面的帮助将不胜感激!
解决方案
推荐阅读
- javascript - Jquery/Javascript:使用布尔值来确定 if 语句
- android - Xamarin:列表中的 Collection.Remove 是否删除了错误的对象?
- python - 数据框中的回合时间
- css - 只有 css 的标签
- python - Python循环遍历excel表格,将表格名称添加到列表中,然后全部连接
- ruby - ruby chef 食谱数组 &&= 有条件的
- jquery - 如何在 json 中获取正确的 obj?
- apache - 使用 HTTP 协议的 Delphi 回调服务器 几分钟后总是超时
- javascript - 定位圆和箭头
- amazon-web-services - UpdateItem - 访问被拒绝