Skip to content

Latest commit

 

History

History
87 lines (77 loc) · 2.29 KB

README.md

File metadata and controls

87 lines (77 loc) · 2.29 KB

react-native-azure-blob-storage

Getting started

$ npm install react-native-azure-blob-storage --save

Mostly automatic installation

$ react-native link react-native-azure-blob-storage

Usage

import React, { Component } from 'react';
import { Button, StyleSheet, ScrollView, View, Image, TouchableOpacity, Platform } from 'react-native';
import { EAzureBlobStorageFile } from 'react-native-azure-blob-storage';
import CameraRoll from "@react-native-community/cameraroll";

 class App extends Component {
  state = {
    photos: []
  }
  async componentDidMount() {
    EAzureBlobStorageFile.configure(
      "Account Name", //Account Name
      "Account Key", //Account Key
      "images", //Container Name
       false //SAS Token 
    );
  }
  _handleButtonPress = () => {
    CameraRoll.getPhotos({
      first: 20,
      assetType: 'Photos',
    })
      .then(r => {
        this.setState({ photos: r.edges });
      })
      .catch((err) => {
        console.log("Errror", err)
      });
  };
  render() {
    return (
      <View>
        <Button title="Load Images" onPress={this._handleButtonPress} />
        <ScrollView>
          {this.state.photos.map((p, i) => {
            return (
              <TouchableOpacity
                onPress={ () => {
                   EAzureBlobStorageFile.uploadFile({
                              "filePath":Platform.OS === 'android'?filePath:'file://' + filePath,
                              "contentType":"audio/wav",
                              "fileName":"test.wav"
                            }).then((name) => {  
                              console.log('File Name  ' + name);  
                            }).catch((error) => {  
                                console.log('Error' + error); 
                            }); 
                }}
              >
                <Image
                  key={i}
                  style={{
                    width: 300,
                    height: 100,
                  }}
                  source={{ uri: p.node.image.uri }}
                />
              </TouchableOpacity>
            );
          })}
        </ScrollView>
      </View>
    );
  }
}

Example

Ios requires a relative path Android Will work with either 
EAzureBlobStorageImage.uploadFile('/Route To Image.PNG'')