天天看點

上傳圖檔格式為base64

後端設定base64格式的圖檔

前提:下載下傳node.js

安裝

導入js腳本

上傳圖檔格式為base64
chooseimg() {
				var that = this;
				uni.chooseImage({//必須要使用的控件
					success: (res) => {
						pathToBase64(res.tempFilePaths[0])
							.then(base64 => {
								console.log(base64);
								let image = base64;
								uni.request({
									url: that.baseUrl + '/api/other/imageUpload',//接口的路徑
									data: {
										images: image
									},
									header: {
										"content-type": "application/x-www-form-urlencoded"
									},
									method: 'POST',
									success: function(res) {
										that.images = that.baseUrl + res.data.data;
										console.log(res)
									}
								})
							})
							.catch(error => {
								console.error(error);
							});
					}
				});
			}
           

繼續閱讀