Uploading file into azure blob storage using Azure Keyvault credentials with NodeJS and React - Part 2
In case you missed Part 1, follow this link below
Uploading file into azure blob storage using Azure Keyvault credentials with NodeJS and React - Part 1
So now let's create the UI using reactJS. Finished app looks like below screenshot, which only has an upload option, you may add other features and fields with validation as you need.
Initiate a react app using command :
create-react-app sample-azure-client-app
Dependency for endpoint call : axios
install via npm i --save axios
Create App component
Use App component in index.js
So that is it, we are done, hope this helps. Comment below in case of any issues you are facing.
Uploading file into azure blob storage using Azure Keyvault credentials with NodeJS and React - Part 1
So now let's create the UI using reactJS. Finished app looks like below screenshot, which only has an upload option, you may add other features and fields with validation as you need.
Initiate a react app using command :
create-react-app sample-azure-client-app
Dependency for endpoint call : axios
install via npm i --save axios
Create App component
import React from 'react';
import UploadImage from './assets/upload.png'
import axios from 'axios'
const onChange = e => {
const files = Array.from(e.target.files)
const currentFile = files[0]
const formData = new FormData()
formData.append('file',currentFile)
axios({
url:'http://localhost:3001/upload/file',
method:'POST',
params:null,
data:formData,
headers:null
}).then( res => {
alert(JSON.stringify(res))
}).catch(err => {
alert(JSON.stringify(err))
})
}
const App = () => {
return (
<div style={Styles.container}>
<label>
<img src={UploadImage} alt='' style={Styles.uploadImage} />
<div>Upload File</div>
<span><input type="file" name='' style={Styles.file} onChange={onChange}/></span>
</label>
</div>
);
}
export default App;
const Styles = {
file:{
display:'none'
},
uploadImage:{
width:50,
height:50
},
container:{
textAlign:'center',
margin:40
}
}
Use App component in index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
serviceWorker.unregister();
So that is it, we are done, hope this helps. Comment below in case of any issues you are facing.

Comments
Post a Comment