如何使用 react-native 将文件上传到服务器 [英] How to upload file to server using react-native
本文介绍了如何使用 react-native 将文件上传到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个应用程序,我需要将图像上传到服务器.根据图像,我得到了需要渲染的响应?
I am developing a app where i need to upload an image to the server. Based on the image i get a response which i need to render?.
你能帮我如何使用 react-native 上传图片吗?
Can you please help me how to upload an image using react-native?.
推荐答案
React Native 内置文件上传功能.
There is file uploading built into React Native.
示例来自 React Native代码:
Example from React Native code:
var photo = {
uri: uriFromCameraRoll,
type: 'image/jpeg',
name: 'photo.jpg',
};
var body = new FormData();
body.append('authToken', 'secret');
body.append('photo', photo);
body.append('title', 'A beautiful photo!');
var xhr = new XMLHttpRequest();
xhr.open('POST', serverURL);
xhr.send(body);
这篇关于如何使用 react-native 将文件上传到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文