javascript - 当我将图像上传到 django 中的数据库时,nonetype' 对象没有属性 'decode' 错误
问题描述
我是 ionic4/angular4 的新手。我需要将配置文件图片上传到数据库。我编写了代码,但我不知道它是否正确,当我上传它时,我收到了上述错误。他正在使用 Django 的后端,并且后端是正确的,只有其他请求正在接受。抱歉缩进不好。
.ts
getPicture() {
const options: CameraOptions = {
quality: 70,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
allowEdit: false,
sourceType: this.camera.PictureSourceType.CAMERA,
correctOrientation: true,
saveToPhotoAlbum: false
};
this.camera.getPicture(options).then(
imageData => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
this.image = this.sanitizer.bypassSecurityTrustUrl(
"data:Image/*;base64" + imageData
);
// this.imageURI = imageData;
this.profileService
.postInfluencerProfile(this.image, null, null)
.subscribe(
response => {
console.log(response);
},
(error: MavinError) => {
if (error instanceof NotFoundError) {
alert("Not found");
} else {
console.log(error);
}
}
);
},
err => {
// Handle error
}
);
}
服务.ts
postInfluencerProfile(
profilePic: File,
name: string,
emailId: string
): Observable<any> {
const url = "****************";
const apiKey = "************";
const sessionID = localStorage.getItem("sessionID");
const formdata = new FormData();
formdata.append("file", profilePic);
console.log(formdata);
const loginContext = {
user_agent:
"Dalvik/2.1.0 (Linux; U; Android 6.0.1; Nexus Player Build/MMB29T)"
};
const postData = {
api_key: apiKey,
session_id: sessionID,
profile_picture: profilePic,
display_name: name,
email_id: emailId
};
const httpOptions = {
headers: new HttpHeaders({
"Content-Type": "multipart/form-data;"
})
};
// delete httpOptions.headers['Content-Type'];
console.log(postData);
return this.http.post(url, postData, httpOptions);
}
解决方案
推荐阅读
- pyspark - 来自 Google Dataproc 上 Cloudkarfka 的 PySpark 流式传输
- javascript - 使用 Immutability helper js 更新对象数组中对象内的元素
- android - 我的应用程序在运行时工作,但在“应用更改并重新启动活动”时崩溃
- php - 如何在 Codeigniter 3 中自定义错误页面 500?
- python - 使用 python 在 Chrome 中将 HTML 文件另存为 PDF 时,页面大小规范不起作用
- c - 构建时打开了错误的库
- django - 有没有办法让枚举类型的文本选择字段接受具有人类可读值的传入帖子请求?
- google-apps-script - 如何使用 Findall 函数从 Row 获取 a1Notations
- javascript - react-native expo错误:未处理的承诺拒绝:TypeError:null不是对象(评估'RNAlarmNotification.scheduleAlarm')
- unit-testing - 如何在单元测试中测试被测方法内部调用的方法/查询的返回值?