简体   繁体   English

React-Native 推送到 AWS S3

[英]React-Native push to AWS S3

I am working on a React-Native App client that needs to generate a JSON file and send it to a s3 bucket.我正在开发一个需要生成 JSON 文件并将其发送到 s3 存储桶的 React-Native 应用程序客户端。 I don't quite know how to do the two steps of this process:我不太清楚如何执行此过程的两个步骤:

First I'd need o be able to generate a JSON file with some variables from my App.首先,我需要能够从我的应用程序中生成带有一些变量的 JSON 文件。 For these I found https://www.npmjs.com/package/react-native-fs .对于这些,我找到了 https://www.npmjs.com/package/react-native-fs The problem is I don't quite know if it would work correctly, or even where it would save the file.问题是我不太清楚它是否能正常工作,甚至不知道它将文件保存在哪里。 I wouldn't want to pollute the user's phone, and rather have the file be stored in a safe location.我不想污染用户的手机,而是将文件存储在安全的位置。

Then I'd need to be able to send this file over to the S3 bucket.然后我需要能够将此文件发送到 S3 存储桶。 I think https://www.npmjs.com/package/react-native-aws3 is the best option, but I'm not sure if it is.我认为https://www.npmjs.com/package/react-native-aws3是最好的选择,但我不确定是否是。

What would be the recommended way to do this?推荐的方法是什么?

Definitely using the official AWS Javascript SDK is the best way of doing it.绝对使用官方AWS Javascript SDK 是最好的方法。 As you may know react native lives in the javascript thread and so you can use already made javascript libraries and sdks.如您所知,React Native 存在于 javascript 线程中,因此您可以使用已经制作的 javascript 库和 sdk。 ( This may not be always true but in this case it is ) (这可能并不总是正确的,但在这种情况下它是)

Take a look at this AWS article on how to use their Javascript SDK in react native. 看看这篇 AWS 文章,了解如何使用他们的 Javascript SDK 进行原生反应。

And then you could use this method in the sdk for uploading your JSON object to an S3 bucket without having to actually create the file in the device before uploading it.然后您可以在 sdk 中使用此方法将您的 JSON object 上传到 S3 存储桶,而无需在上传之前在设备中实际创建文件。 The sdk takes care of it for you. sdk 为您处理。

s3.putObject({
      Bucket: 'currenteventstest',
      Key: 'users.json',
      Body: JSON.stringify(users),
      ContentType: "application/json"},
      function (err,data) {
        console.log(JSON.stringify(err) + " " + JSON.stringify(data));
      }
    );

Method for node js aws sdk for uploading a JSON object to S3 object 用于将 JSON object 上传到 S3 ZA8CFDE6331BD59EB66AC96F8911C4 的节点 js aws sdk 的方法

React-native 通过 Json 值反应原生<input< div><div id="text_translate"><h2> <strong>大家好,</strong></h2><p> 我只是从 react-native 开始为 android cel 创建一个应用程序。 我有一个包含 2 个字段 / 的表单,我想从 json 加载这些字段,这些字段是从 php 文件中提取的。 如果我只通过 json 发送一个值,我可以使用“componentDidMount”和“XMLHttpRequest()”在一个字段中加载该值这是我在 componentdidmount 使用的代码:</p><pre> componentDidMount=()=&gt; { let _this= this; const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 &amp;&amp; this.status == 200){ console.log(this.responseText); var temp = JSON.parse(xhttp.responseText); console.log(temp); _this.setState({datos: temp}); } }; xhttp.open('GET', 'https://smppage.000webhostapp.com/gest_ObtFolio2.php', true); xhttp.send(); }</pre><p> 这些是 console.log 中打印的值: responsetext: LOG [{"iddeOS":"13"},{"fecha":"2021-12-04"}] temp: LOG [{"iddeOS": "13 "}, {"fecha": "2021-12-04"}]</p><p> 当我只通过 json 发送一个字段时,我可以将它加载到一个字段中,但我想通过 json 发送 2 个字段,这是我通过 json 发送的值,仅用于一个字段:LOG14:响应文本:是我在一个中使用的代码/当我只拉一个字段并且该字段正确加载到我的</p><pre> &lt;View style={{flex:1}}&gt; &lt;Input ref={component =&gt; this.folioOrden = component} label=" Folio" value={this.state.datos.toString()}</pre><p> 使用此代码,它可以正确地将值加载到一个字段中</p><p>你能帮忙找到代码来同时填充“Folio”和“Fecha”这两个字段并安装组件吗?</p><pre> &lt;View style={{flex:1}}&gt; &lt;Input ref={component =&gt; this.folioOrden = component} label=" Folio" value={this.state.datos.toString()} &lt;View style={{flex:2}}&gt; &lt;Input ref={component =&gt; this.fechaAperOrden = component} label=" Fecha"</pre><p> 我已经尝试发送 2 个字段并在两个输入中使用此代码,但我显示错误:</p><pre> value={this.state.datos.iddeOS.toString()} value={this.state.datos.fecha.toString()}</pre><p> 提前致谢</p></div></input<> - React-native pass Json values to react native <input

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 react-native中的JSON解析 - JSON parsing in react-native React-Native:解析JSON - React-Native: Parsing JSON 从本机发布 - Post from react-native 我可以使用AWS Glue将S3上的json数据转换为列格式并将其推送到Redshift吗? - Can I use AWS Glue to convert json data on S3 to columnar format and push it to Redshift? React-native 通过 Json 值反应原生<input< div><div id="text_translate"><h2> <strong>大家好,</strong></h2><p> 我只是从 react-native 开始为 android cel 创建一个应用程序。 我有一个包含 2 个字段 / 的表单,我想从 json 加载这些字段,这些字段是从 php 文件中提取的。 如果我只通过 json 发送一个值,我可以使用“componentDidMount”和“XMLHttpRequest()”在一个字段中加载该值这是我在 componentdidmount 使用的代码:</p><pre> componentDidMount=()=&gt; { let _this= this; const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 &amp;&amp; this.status == 200){ console.log(this.responseText); var temp = JSON.parse(xhttp.responseText); console.log(temp); _this.setState({datos: temp}); } }; xhttp.open('GET', 'https://smppage.000webhostapp.com/gest_ObtFolio2.php', true); xhttp.send(); }</pre><p> 这些是 console.log 中打印的值: responsetext: LOG [{"iddeOS":"13"},{"fecha":"2021-12-04"}] temp: LOG [{"iddeOS": "13 "}, {"fecha": "2021-12-04"}]</p><p> 当我只通过 json 发送一个字段时,我可以将它加载到一个字段中,但我想通过 json 发送 2 个字段,这是我通过 json 发送的值,仅用于一个字段:LOG14:响应文本:是我在一个中使用的代码/当我只拉一个字段并且该字段正确加载到我的</p><pre> &lt;View style={{flex:1}}&gt; &lt;Input ref={component =&gt; this.folioOrden = component} label=" Folio" value={this.state.datos.toString()}</pre><p> 使用此代码,它可以正确地将值加载到一个字段中</p><p>你能帮忙找到代码来同时填充“Folio”和“Fecha”这两个字段并安装组件吗?</p><pre> &lt;View style={{flex:1}}&gt; &lt;Input ref={component =&gt; this.folioOrden = component} label=" Folio" value={this.state.datos.toString()} &lt;View style={{flex:2}}&gt; &lt;Input ref={component =&gt; this.fechaAperOrden = component} label=" Fecha"</pre><p> 我已经尝试发送 2 个字段并在两个输入中使用此代码,但我显示错误:</p><pre> value={this.state.datos.iddeOS.toString()} value={this.state.datos.fecha.toString()}</pre><p> 提前致谢</p></div></input<> - React-native pass Json values to react native <input 在 react-native 中迭代 JSON 数组 - iterate over JSON array in react-native React-Native 获取 XML 数据 - React-Native fetch XML data 无法使用地图功能react-native - Not able to use map function react-native React-Native 需要中断生产警告 - React-Native Requiring BREAK IN PRODUCTION Warning React-Native中的JSON对象中的JSON对象 - JSON object in JSON object in React-Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM