如何使用react-native的fetch api将文件上传到服务器 需要实现与此类似的东西 – ------WebKitFormBoundaryRAxza9ew2ADaYHn5Content-Disposition: form-data; name="file"; filename="66154520.jpg"Content-Type: image/jpeg------
需要实现与此类似的东西 –
------WebKitFormBoundaryRAxza9ew2ADaYHn5 Content-Disposition: form-data; name="file"; filename="66154520.jpg" Content-Type: image/jpeg ------WebKitFormBoundaryRAxza9ew2ADaYHn5--你没有展示任何类型的代码,但理论上……
您应该将URL从ImagePicker或CameraRoll(应该类似于file:///storage/emulated/0/Pictures/shj15791-4v61-67g6-z1b6-v8451z956j5k.jpg)传递给formData,然后将其与请求:
const form = new FormData(); form.append('image', { uri: "file:///...", type: 'image/jpg', name: 'image.jpg', }); fetch('https://example.com/api/upload', { method: 'POST', body: form });