Home > Back-end >  How to upload JSON file to react web-app and get the link to the file
How to upload JSON file to react web-app and get the link to the file

Time:11-23

How can I upload JSON file to my react app and get the link to the JSON file? My app dev is trying to do app linking and said that is what he needs

CodePudding user response:

About your question

For anyone to comprehensibly answer your question, you need to give more information (as per the Picture of json data

The app developer would then need to web scrape the site to access the JSON.

This satisfies your original request involving an approach involving a URL to the file, but if the file is static then you could just send it directly to the app developer without uploading it, which would be much easier and more efficient as web scraping is quite slow.

CodePudding user response:

when received your JSON file, then display in browser

const [ JsonFile, setJsonFile ] = useState({})

const uploadFile = (event)=>{
const reader = new FileReader();
    reader.onload = function(){
    window.location.href = reader.result;
        }
reader.readAsDataURL(event.target.files[0]);
setJsonFile(event.target.files[0]);
}

get your JSON file from client

<input type="file" onChange={uploadFile} />
  • Related