【问题标题】:Delete images from gallery using react-native-image-picker使用 react-native-image-picker 从图库中删除图像
【发布时间】:2019-07-16 11:38:45
【问题描述】:

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

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

我的代码是,

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>
    );
  }
}

【问题讨论】:

  • 嗨!你能解释一下你到目前为止所做的尝试吗?

标签: react-native react-native-android


【解决方案1】:

安装 react native react-native-fs 这有助于删除你的图像。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    • 1970-01-01
    • 2019-05-29
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    相关资源
    最近更新 更多