2016-11-23 42 views
3

如何上传文件使用反应本地的提取API 需要实现类似的东西到这个 -上传图像反应母语

------WebKitFormBoundaryRAxza9ew2ADaYHn5 
Content-Disposition: form-data; name="file"; filename="66154520.jpg" 
Content-Type: image/jpeg 


------WebKitFormBoundaryRAxza9ew2ADaYHn5-- 
+0

http://stackoverflow.com/questions/32441963/how-to-use-formdata-in-react-native的可能重复。 –

+0

我们使用base64从设备上传图像到服务器。这样我们发送的数据总是相同的类型 - 不需要为每个不同的格式图像(jpg,png,bmp等)定义不同的类型。我们从来没有任何问题,在服务器上只是从base64转换回来。 –

回答

1

你没有表现出任何类型的代码服务器,但在理论上...

你应该像ImagePickerCameraRoll(这应该类似于file:///storage/emulated/0/Pictures/shj15791-4v61-67g6-z1b6-v8451z956j5k.jpg)通过URL来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 
});