【问题标题】:react-native-image-picker how to save image with customize filenamereact-native-image-picker 如何使用自定义文件名保存图像
【发布时间】:2018-11-14 03:52:36
【问题描述】:

我正在尝试使用 react-native 开发一个 android 应用程序。其中一项要求是以编程方式根据预定义的文件名自动保存捕获的图像。我正在使用 react-native-image-picker。

图像选择器的 API 没有显示以编程方式使用每个定义的文件名保存图像的方法。我正在使用的教程也没有显示。

非常感谢。

【问题讨论】:

    标签: android react-native react-native-image-picker


    【解决方案1】:

    我是这样做的。这可能会对您有所帮助。

    ImagePicker.launchCamera({},(responce)=>{
          this.setState({
              pickedImage: { uri: res.uri }
            });
          console.log(this.state.serverTime);
          const file ={
            uri : responce.uri,
            //give the name that you wish to give
            name :this.state.currentTimeInMilisec+'.jpg',
            method: 'POST',
            path : responce.path,
            type :  responce.type,
            notification: {
                enabled: true
              }
          }
           console.log(file);
        })
      }
    

    【讨论】:

      【解决方案2】:

      我做了如下。它工作正常。

      ImagePicker.launchCamera({},(responce)=>{
            const localTime = new Date().getTime();
            const file ={
              uri : responce.uri,
              //give the name that you wish to give
              name :localTime +'.jpg',
              method: 'POST',
              path : responce.path,
              type :  responce.type,
              notification: {
                  enabled: true
                }
            }
             console.log(file);
          })
        }
      

      【讨论】:

      • 感谢您提供此代码 sn-p,它可能会提供一些有限的即时帮助。 proper explanation 将通过展示为什么这是解决问题的好方法,并使其对有其他类似问题的未来读者更有用,从而大大提高其长期价值。请edit您的回答添加一些解释,包括您所做的假设。
      • 当然,德惠兹。 :)
      猜你喜欢
      • 1970-01-01
      • 2020-03-13
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多