Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

upload file to database with axios and formData

  //submit file to database
  const handleSubmit = (e) => {
    e.preventDefault()
    //use formdata to submit form to database
    const formData = new FormData()
    formData.append('mda', mdaName)
    formData.append('logo', file)
    axios({
      method: 'post',
      url: 'https://aaerlaw.herokuapp.com/api/admin/mdas',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    })
      .then((res) => {
        console.log(res)
        alert.success('MDA added successfully')
        setMdaName('')
        setFile('')
      })
      .catch((err) => {
        console.log(err)
      })
  }
Comment

PREVIOUS NEXT
Code Example
Javascript :: Promises ex. 
Javascript :: jquery ajax download file 
Javascript :: javascript tostring 
Javascript :: generator function javascript 
Javascript :: model export in node js 
Javascript :: get downloadable link to s3 bucket object js 
Javascript :: Using flat() method 
Javascript :: get browser cookie 
Javascript :: max method in js 
Javascript :: js add data in object 
Javascript :: export aab bundle react native android 
Javascript :: C# Convert Json File to DataTable 
Javascript :: clearinterval javascript 
Javascript :: login with facebook in react 
Javascript :: audio element javascript 
Javascript :: big o notation javascript 
Javascript :: props comment 
Javascript :: edit embeds discord.js 
Javascript :: javascript iterate through object attributes 
Javascript :: how to access data in json format using asp.net c# 
Javascript :: greater than x but less than y javascript 
Javascript :: new array from javascript 
Javascript :: highlight nav menu on scroll with javascript 
Javascript :: vue css 
Javascript :: Create Your Own Node Module 
Javascript :: how to find the lowest number in an array in javascript for specific indexes 
Javascript :: js access array in array 
Javascript :: jq get value without quotes 
Javascript :: javascript remove index from array 
Javascript :: passing multiple props to child component in react 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =