File upload 如何在Nativescript Vue中上载文件

File upload 如何在Nativescript Vue中上载文件,file-upload,vuejs2,nativescript,nativescript-vue,File Upload,Vuejs2,Nativescript,Nativescript Vue,我正在使用NativeScript Vue 2 NativeScript 4.2.2 我需要通过API将一个文件从应用程序上传到PHP服务器 这是我使用的代码。。。服务器似乎以[object]的形式获取文件 从“tns核心模块/ui/Image”导入{Image}; 从“tns核心模块/文件系统”导入{File,knownFolders,path}; 从“tns核心模块/图像源”导入{ImageSource}; 从“nativescript camera”导入*作为摄像头; 从“natives

我正在使用NativeScript Vue 2 NativeScript 4.2.2

我需要通过API将一个文件从应用程序上传到PHP服务器

这是我使用的代码。。。服务器似乎以[object]的形式获取文件

从“tns核心模块/ui/Image”导入{Image}; 从“tns核心模块/文件系统”导入{File,knownFolders,path}; 从“tns核心模块/图像源”导入{ImageSource}; 从“nativescript camera”导入*作为摄像头; 从“nativescript imagepicker”导入*作为imagepicker; 导出默认值{ 资料{ 返回{ 值:null, }; }, 方法:{ 选择图片{ const context=imagepicker.create{ 模式:this.multiple?'multiple':'single', 最小NumberOfSelection:1, 最大NumberOfSelection:1, }; 上下文 批准 .then=>context.present .thenselection=>{ selection.forEachselected=>{ 设imageSource=新imageSource; imageSource.fromAssetselected .然后=>{ 如果选中,则为.android{ this.saveFileselected.android.toString; }否则{ const ios=selected.ios; 如果ios.mediaType===PHAssetMediaType.Image{ const opt=PHImageRequestOptions.new; opt.version=PHImageRequestOptionsVersion.Current; PHImageManager.defaultManager .RequestImageDataforAssetOptions ResultHandlerIOS、opt、imageData、dataUTI、方向、信息=>{ 这个.saveFileinfo.objectForKey'PHImageFileURLKey'.toString; }; } } }; }; }; }, saveFilesource,saveIt=false{ 常量图像=新图像; const folderPath=knownFolders.documents.path; image.src=源; const fileName=image.src.toString.split'/'.pop; const filePath=path.joinfolderPath,文件名; 如果保存它{ 常量imageSource=新的imageSource; const saved=imageSource.savetofilepath,“png”; 如果!得救了{ console.log“[UploadFile]-无法保存文件!”; } } this.value=File.fromPathfilePath; console.log“[UploadField]->”,文件名; }, 提交{ const params=新表单数据; params.append'file',this.value; axios{ 标题:{ “内容类型”:“多部分/表单数据”, }, 方法:“POST”, params, } .thenresponse=>console.logresponse; }, }, };
常规XHR axios请求不支持多部分内容类型。有一个问题,您可能希望注册您的投票并订阅该问题以获得进一步更新


同时,解决方法是将文件内容发布为base64字符串或使用支持多部分上传的插件。

请删除不必要的文本,这些文本会降低文件质量question@SebaGra我希望我能。。。Stackoverflow不允许我在没有额外内容的情况下提交。打他们-非常感谢。我确实看到了那些nativescript背景http示例,但从未看到它是唯一的解决方法。。。