ionic-framework - 上传图片文件而不是base 64
问题描述
我需要上传一张图片到我的服务器上的一个文件夹。所以我需要上传图像文件,它不能在base 64上。我正在尝试使用文件传输但是它返回错误1并且文件路径获取为'不安全:C:\ fakepath'。
上传文件的代码出错:
AnexoUpload() {
const fileTransfer: FileTransferObject = this.transfer.create();
let options: FileUploadOptions = {
fileKey: 'ionicfile',
fileName: 'ionicfile',
chunkedMode: false,
mimeType: "image/jpeg",
headers: {},
params: {
'contemArq': 'S',
'id': this.IdAnexo,
'fileAnexo': this.file
// the rest of your form fields go here, except photo
}
};
fileTransfer.upload(this.img, 'http://localhost:61473/api/v1/cadastros/despesa/anexo', options)
.then((data) => {
this.retornoMsg(data);
}, (err) => {
this.retornoErro(err);
});
}
fileEvent(e){ // Change of input type file
this.file = e.target.files[0];
}
看法:
<input type="file" [(ngModel)]="ImgArq" (change)=fileEvent($event)/>
解决方案
推荐阅读
- javascript - 在 chrome 扩展中使用时捕获的视频帧中的单个图像后,有什么方法可以停止 MediaRecorder 对象?
- html - 如何防止命名空间 HTML 元素的 Vue 错误“未知自定义元素”
- php - 调整窗口大小时如何修复侧边栏?
- html - 带有打字稿的响应式画布元素
- bash - 如何检查字符串是否不包含某些字符?
- json - 如果字典中有多个 json 字段具有相同名称,如何获取值?
- angular - 离子项目可点击属性不起作用(Ionic 4)
- azure-service-fabric - 如何将外部(打包)Service Fabric 服务添加到应用程序清单
- ios - 插入耳机后我只能听到录音机音频
- python-3.x - 奇异矩阵的逆