Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
React - Sending uploaded images as url to an API

I am sending multiple images to an API but the way I do it sends it as an object but I need to send it as a URL.

State:

const [files, setFiles] = useState([]);

Image uploader:

 const fileSelectHandler = (e) => {
        setFiles([...files, ...e.target.files]);
      };

<input
  type="file"
  className="form-control"
  id="customFile"
  multiple
  onChange={fileSelectHandler}
/>

Expected sending package:

"pic": [
            {
                "url": "760634d2-f8ec-4caa-9a2d-14a8828cfb5dpetplace.jpg"
            },
            {
                "url": "760634d2-f8ec-4caa-9a2d-14a8828cfb5dpetplace.jpg"
            }
       ]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can solve it like this:

import React from "react";

export default function App() {
  const [files, setFiles] = React.useState([]);

   const fileSelectHandler = (e) => {
   const [file] = e.target.files;
   setFiles([...files, { url: file.name }]);
  };

  const picObj = { pic: files };
  console.log(picObj);
  return (
    <div className="App">
      <input
        type="file"
        className="form-control"
        id="customFile"
        multiple
        onChange={fileSelectHandler}
      />
 
    </div>
  );
}

Here alink to the demo: https://codesandbox.io/s/immutable-pine-2k8t9?file=/src/App.js:0-625

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!