首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用react-native-image-picker从图库中删除图像

使用react-native-image-picker从图库中删除图像
EN

Stack Overflow用户
提问于 2019-02-22 19:24:17
回答 1查看 2.8K关注 0票数 3

我已经创建了一个应用程序,使用react-native-image-picker捕捉照片并上传到亚马逊s3。上传完成后,我想从图库中删除它们。当我搜索clean应用编程接口文档时,我了解了imagePicker ()方法。但是我不知道如何在我的代码中使用它。

你能帮我解决这个问题吗?

我的代码是,

代码语言:javascript
复制
import React, { Component } from "react";
import {
  Platform,
  StyleSheet,
  Alert,
  Text,
  TouchableOpacity,
  View,
  Picker,
  Animated,
  Easing,
  Image
} from "react-native";
import ImagePicker from "react-native-image-picker";
import { RNS3 } from "react-native-aws3";

export default class SecondScreen extends Component<Props> {
  constructor(props) {
    super(props);
    this.state = {
      file: "",
      saveImages: []
    };
  }

  takePic() {
    const options = {
          quality: 1.0,
          maxWidth: 50,
          maxHeight: 50,
      }
    ImagePicker.launchCamera(options,(responce)=>{
      const file = {
        uri: responce.uri,
        name: responce.fileName,
        method: "POST",
        path: responce.path,
        type: responce.type,
        notification: {
          enabled: true
        }
      };
      this.state.saveImages.push(file);
    });
  }
  _upload = saveImages => {
    const config = {
      keyPrefix: "uploads/",
      bucket: "s3merahkee",
      region: "us-east-2",
      accessKey: "***",
      secretKey: "***",
      successActionStatus: 201
    };

    this.state.saveImages.map(image => {
      RNS3.put(image, config).then(responce => {
        console.log(saveImages);
      });
    });

    //once after upload is done delete from the gallary
  };
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.Camera}>
          <TouchableOpacity onPress={this.takePic.bind(this)}>
            <Text>Take Picture</Text>
          </TouchableOpacity>
        </View>
        <View style={styles.Send}>
          <TouchableOpacity onPress={() => this._upload()}>
            <Text>Send</Text>
          </TouchableOpacity>
        </View>
      </View>
    );
  }
}
EN

回答 1

Stack Overflow用户

发布于 2019-02-22 19:34:31

安装react native react-native-fs这有助于删除您的镜像。

代码语言:javascript
复制
import { RNCamera } from 'react-native-camera';
import RNFS from 'react-native-fs';

takePhoto = async () => {
  const data = await this.camera.takePictureAsync();
  // Do what you need with the image and then…
  RNFS.unlink(data.uri); // Remove image from cache
}

另请参阅此https://github.com/itinance/react-native-fs/issues/34

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54826023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档