我的 React Native 应用程序使用该库接收选定的图像react-native-image-picker,我需要将该图像发送到运行 NestJS 服务器的后端。端点使用@UseInterceptor和FileInterceptor从收到的 formData 的“文件”字段中提取图像。但是,当我向端点发出请求时,收到的文件未定义。
这是我的 React Native 代码,发送请求并将 FormData 中的文件作为有效负载。
\nconst uploadNewProfileImage = async () => {\n if (!newProfileImage?.assets) return;\n const formData = new FormData();\n const profileImage = newProfileImage.assets[0];\n console.log(profileImage);\n if (profileImage.uri && user) {\n formData.append(\n 'file',\n JSON.stringify({\n uri:\n Platform.OS === 'android'\n ? profileImage.uri\n : profileImage.uri.replace('file://', ''),\n name: profileImage.fileName,\n type: profileImage.type\n })\n );\n client // client is an Axios instance that injects Bearer Token\n .post(`/user/profile/${user.uid}/image`, formData)\n .then(({ data …Run Code Online (Sandbox Code Playgroud)